- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
delphi动态创建窗体
delphi动态创建窗体
Delphi中动态创建窗体有四种方式,最好的方式如下:
比如在第一个窗体中调用每二个,主为第一个,第二个设为动态创建
Uses Unit2; //引用单元文件
procedure TForm1.Button1Click(Sender: TObject);
begin
form2:=TForm2.Create(Application); //创建窗体
form2.Show; //显示窗体
end;
end.
======================================================
最好不要用另外三种:
Application.CreateForm(TForm2,Form2);
form2:=TForm2.Create(Self);
form2:=TForm2.Create(nil);
Delphi窗体创建大揭密
1. 窗体权限的转移实验
新建3个Form , 在Project-Options… 中的Forms 一页把Form2和Form3 放置在 Available forms中,保留Form1在Auto-create forms中,让Form1在程序一开始运行就创建。
在Form1(主窗体)中的OnCreate()事件函数中加入以下代码:
procedure TForm1.FormCreate(Sender: TObject);
begin
Label1.Caption:=Form1 Create Completed!;
Form1.Show;
Application.CreateForm(TForm2, Form2);
end;
(代码2)
在Form2的OnCreate()事件函数中加入以下代码:
procedure TForm2.FormCreate(Sender: TObject);
begin
Label1.Caption:=Form2 Create Completed!;
Form2.Show;
Application.CreateForm(TForm3,Form3);
end;
(代码3)
在Form3的OnCreate()事件函数中加入以下代码:
procedure TForm2.FormCreate(Sender: TObject);
begin
Label1.Caption:=Form3 Create Completed!;
Form3.Show;
end;
(代码4)
这个程序在运行后将显示三个窗体,分别是Form1,Form2,和Form3。你可能在想,如果要关闭程序,只要关闭Form1这个主窗体就可以了。然而你错了,应该是关闭Form3才能将整个程序关闭。为什么呢?关键在CreateForm()这个窗体创建函数,查一下Delphi的随机帮助文件就清楚了。帮助文件有关CreateForm()函数的说明如下:
Call CreateForm to dynamically create a form at runtime. Developers do not need to add code for creating most forms, because typically one or more calls to CreateForm are added automatically to the projects main source when using the form designer.
CreateForm creates a new form of the type specified by the FormClass parameter and assigns it to the variable given by the Reference parameter. The owner of the new form is the Application object.
Note: By default, the form created by the first call to CreateForm in a project becomes the application’s main form.
文档评论(0)