主窗体form1:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
Tfrm=class of TForm;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure Showfrm(Frmclass:Tfrm; FrmValue:TForm);
end;var
Form1: TForm1;implementation
uses unit2,unit3,unit4;
const
ArrFrm:array[0..2] of Tfrm=(Tform2,Tform3,Tform4);
{$R *.dfm}
procedure TForm1.Showfrm(Frmclass:Tfrm; FrmValue:TForm);
begin
if assigned(FrmValue) then
begin
showmessage('存在');
FrmValue.ShowModal;
end
else
begin
FrmValue:=Frmclass.Create(application);
try
FrmValue.Showmodal;
finally
FrmValue.Free; (1)
FrmValue:=nil; (2)
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
showfrm(Tfrm(ArrFrm[0]),form2); //问题是怎么把form2,form3,form4用数组来调用
end; end. (1)与(2)调换一下才不会出现:FrmValue从来没有使用的delphi编译器的提示,但能顺利执行.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
Tfrm=class of TForm;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure Showfrm(Frmclass:Tfrm; FrmValue:TForm);
end;var
Form1: TForm1;implementation
uses unit2,unit3,unit4;
const
ArrFrm:array[0..2] of Tfrm=(Tform2,Tform3,Tform4);
{$R *.dfm}
procedure TForm1.Showfrm(Frmclass:Tfrm; FrmValue:TForm);
begin
if assigned(FrmValue) then
begin
showmessage('存在');
FrmValue.ShowModal;
end
else
begin
FrmValue:=Frmclass.Create(application);
try
FrmValue.Showmodal;
finally
FrmValue.Free; (1)
FrmValue:=nil; (2)
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
showfrm(Tfrm(ArrFrm[0]),form2); //问题是怎么把form2,form3,form4用数组来调用
end; end. (1)与(2)调换一下才不会出现:FrmValue从来没有使用的delphi编译器的提示,但能顺利执行.
showfrm(Tfrm(ArrFrm[0]),form2); //问题是怎么把form2,form3,form4用数
你可以再定義一個數組 保存form2.form3..與
ArrFrm:array[0..2] of Tfrm=(Tform2,Tform3,Tform4);中類型要一一對應 不然會出錯的。
Tfrm=class of TForm;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure Showfrm(FrmClass:TFrm;FrmValue: TForm);
end;var
Form1: TForm1;
VarForm:Tform;Const
ArrFrm:array[0..2] of Tfrm=(Tform2,Tform3,Tform4);implementation{$R *.dfm}{ TForm1 }procedure TForm1.Showfrm(FrmClass:TFrm;FrmValue: TForm);
begin
if assigned(FrmValue) then
begin
showmessage('´æÔÚ');
FrmValue.ShowModal;
end
else
begin
FrmValue:=FrmClass.Create(application);
try
FrmValue.Showmodal;
finally
Freeandnil(FrmValue);
end;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
showfrm(ArrFrm[0],VarForm);
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
Tfrm=class of TForm;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure Showfrm(Frmclass:Tfrm; FrmValue:TForm);
end;var
Form1: TForm1;implementation
uses unit2,unit3,unit4;
const
ArrFrm:array[0..2] of Tfrm=(Tform2,Tform3,Tform4);
{$R *.dfm}
procedure TForm1.Showfrm(Frmclass:Tfrm; FrmValue:TForm);
begin
if not assigned(FrmValue) then
FrmValue:=Frmclass.Create(application);
try
FrmValue.Showmodal;
finally
FreeAndNil(FrmValu);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
showfrm(Tfrm(ArrFrm[0]),form2); //问题是怎么把form2,form3,form4用数组来调用
end; end.