procedure CreateForm(FormClass:TFormClass;Var reference);作用:在应用程序中创建一个新的窗体在其参数中FormClass用来制定窗体类型,而Reference是所建立窗体的一个变量。动态建立窗体program project;...begin application.initialize; application.CreateForm(TForm1,Form1); //省略Form2,Form3的建立 application.Run;end;Unit Unit1;....implementationuses 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);beginif 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;