我不信没有高手,关于窗体的创建。

ball_24 2003-10-17 03:30:38
现有一字符类型的变量str,它存储的是一个窗体的类名,如:TForm1,如何由str将类名为str的窗体创建出来???
解决后可以加分!
...全文
34 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cyh1898 2003-10-18
  • 打赏
  • 举报
回复
up
cqzyf 2003-10-17
  • 打赏
  • 举报
回复
忘了一句
var
OpenWindow :TForm;
cqzyf 2003-10-17
  • 打赏
  • 举报
回复
Function TFrm_Main.PRF_Openwindow(as_Fromname:string):integer;
var
FcType : TFormClass;
Frmname:string;
begin
try
Frmname:= as_Fromname;
FcType := TFormClass(FindClass(Frmname));
Application.CreateForm(Fctype,OpenWindow);
OpenWindow.Showmodal;
except
ShowMessage('Form Type not exist,you must register it first');
end;
Result := 0;
end;
需要在pas文件中加
initialization
RegisterClass(窗体类名);
tiexinliu 2003-10-17
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2348/2348755.xml?temp=.7885706
huojiehai 2003-10-17
  • 打赏
  • 举报
回复
哦,写错了应是
with TForm1.Create do
huojiehai 2003-10-17
  • 打赏
  • 举报
回复
if str = 'TForm1' then
width TForm1.Create do
begin
Showmodual;
free;
end;
zzh54zzh 2003-10-17
  • 打赏
  • 举报
回复
//根据窗体的名字建
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
FreeButton: TButton;
const
NameForm = 'TForm';
begin
i := 2;
TForm.Create(Self).Name := NameForm + IntToStr(i);
with TForm(FindComponent(NameForm + IntToStr(i))) do
begin
ShowModal;
free;
end;
end;
aiirii 2003-10-17
  • 打赏
  • 举报
回复
注册该窗体类 TForm1
然后用 FindComponet() 找到该类, 就下来就很简单了!

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧