打印本文 打印本文 关闭窗口 关闭窗口
TApplication 中CreateForm的用法
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1444  更新时间:2009/4/23 18:25:45  文章录入:mintao  责任编辑:mintao

procedure CreateForm(FormClass:TFormClass;Var reference);
作用:在应用程序中创建一个新的窗体
在其参数中FormClass用来制定窗体类型,而Reference是所建立
窗体的一个变量。
动态建立窗体
program project;
...
begin
  application.initialize;
  application.CreateForm(TForm1,Form1);
  //省略Form2,Form3的建立
  application.Run;
end;
Unit Unit1;
....
implementation
uses
 unit2,unit3;
{$ *.DFM}
Funcation Hasform(a:String):boolean;
 var
  R:Boolean;
  X:Integer;
 Begin
   r:=false;
   for x:=0 to screen.formcount-1 do
     begin
      if screen.forms[x].name =a then
         r:=true;
        
     end;
   result:=r;
 End;

procedure form1.button1click(sender :tobject);
begin
if not hasform(''''form2'''') then
   begin
    applicaton.createform(Tform2,form2);
    showmessage(''''Form2窗体建立!'''');
   end;
end;
procedure form1.button2click(sender:tobject);
begin
 if not hasform(''''Form3'''') then
   begin
   application.createform(Tform3,form3);
   showmessage(''''Form3建立!'''');
   end;
end;

打印本文 打印本文 关闭窗口 关闭窗口