//一个包含两个窗体的例子, 这是工程中的内容: program Project1; uses Forms, Unit1 in 'Unit1.pas' {Form1}, Unit2 in 'Unit2.pas' {Form2}; {$R *.res} begin Application.Initialize; Application.MainFormOnTaskbar := True; Application.CreateForm(TForm1, Form1); Application.CreateForm(TForm2, Form2); Application.Run; end.
// unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} uses Unit2; procedure TForm1.Button1Click(Sender: TObject); var num: Integer; begin num := Screen.FormCount; {当前程序中窗体的个数} ShowMessage(IntToStr(num)); {2} Screen.Forms[1].ShowModal; {显示第二个窗体} {上面这句相当于} //Form2.ShowModal; end; end.