delphi下如何实现如下功能?
假定在软件的主界面上有3个button,点击每个button,都会弹出一个新的窗口,如果3个button都点的话,就分别弹出3个新窗口(每个窗口都有自己的不同内容),连同原来的主界面,总共是4个窗口界面。我尝试用“主窗口下点击button创建新窗口的方法”,但最终只能显示一个窗口,根本不是我想要。请高手指教,先谢了。
[解决办法]
动态创建窗口就可以,做个判断。
如有个form1 form2 form3创建一个窗口按钮中加入如下代码。
if not Assigned(form1) then
form1:=TForm1.Create(Self);
form1.show;
在form1 窗口关闭时 OnClose加上以下代码:
if Assigned(form1) then begin
form1.free;
form1:=nil;
end;
[解决办法]
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TmyForms = class of TForm;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } procedure ShowForm(TForms: TmyForms;var Form: TForm); public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}uses Unit2,Unit3,Unit4;//Form2,Form3,Form4所在单元var Form2,Form3,Form4:TForm;procedure TForm1.ShowForm(TForms: TmyForms;var Form: TForm);begin if not Assigned(Form) then //未建立 Form:=TForms.Create(self)//建立 else ShowWindow(Form.Handle,SW_SHOWNORMAL);//恢复原来尺寸 Form.Show;//显示出来end;procedure TForm1.Button1Click(Sender: TObject);begin ShowForm(TForm2,Form2);end;procedure TForm1.Button2Click(Sender: TObject);begin ShowForm(TForm3,Form3);end;procedure TForm1.Button3Click(Sender: TObject);begin ShowForm(TForm4,Form4);end;end.