procedure CreateMyForm(const FormClassName, FormName : string);
begin
if Application.FindComponent(FormName)=nil then begin
if GetClass(FormClassName) <> nil then
with TForm(TComponentClass(FindClass(FormClassName)).Create(Application)) do begin
Name := FormName;
Show;
end
else ShowMessage(Format('类%s未注册',[FormClassName])); end
else begin
ShowMessage(Format('窗体%s已创建过',[FormName]));
TForm(Application.FindComponent(FormName)).Show;
end;
begin
if Application.FindComponent(FormName)=nil then begin
if GetClass(FormClassName) <> nil then
with TForm(TComponentClass(FindClass(FormClassName)).Create(Application)) do begin
Name := FormName;
Show;
end
else ShowMessage(Format('类%s未注册',[FormClassName])); end
else begin
ShowMessage(Format('窗体%s已创建过',[FormName]));
TForm(Application.FindComponent(FormName)).Show;
end;
end;
http://bbs.csdn.net/topics/110082685
本文介绍了一个使用Delphi创建窗体的过程。该过程检查窗体是否已经存在,如果不存在则通过类名创建新的窗体并显示;若已存在,则直接显示已有窗体。此方法避免了重复创建相同名称的窗体。

2240

被折叠的 条评论
为什么被折叠?



