你的问题是很正常的。 你说在Form3,Form4再重新创建Form1。这是的Form1肯定不是Form2创建的Form1了。这些Form1只是同一个类(TForm1)的不同实例 如果你想在Form3,4里引用Form2创建的Form1。那么你可以把Fomr1设成全局变量,然后再Form3,4里引用Form2这个单元,这样就可以直接调用Form1了。 但是还有一点要注意: 在Form3,4并不知道Form1是否创建的时候要调用最好加上一段保护代码: if not Assigned(Form1) then //如果Form1没有创建的话; else //如果Form1没有创建了
begin with TForm.Create(Application) do try ShowModal; fianlly Free; end; end;
这是我动态创建窗体的例程 用Delphi动态几个相同的窗体 1.先定原窗体名如: uses Outputtest 2.在定义几个该窗体的变量 Test1Form,Test2Form,Test3Form:TOutputTestForm; 同时定义对应的几个布尔变量: Test1,Test2,Test3:Boolean; 3.在对应的事件中加入 if not Test1 then begin test1Form := TOutputTestForm.Create(Application); test1Form.Caption :='test1'; test1Form.ShowCaption(1); end else Test1Form.WindowState :=wsNormal; test1Form.show; 4. procedure TOutputTestForm.ShowCaption(Captions: Integer); begin FormFlag:=Captions; Name:='Test'+InttoStr(captions)+'Form'; case captions of 1: begin caption:='窗体'+InttoStr(captions); MainMDIForm.test1:=True; end; 2: begin caption:='窗体'+InttoStr(captions); MainMDIForm.test2:=True; end; 3: begin caption:='窗体'+InttoStr(captions); MainMDIForm.test3:=True; end; end; Left :=0; Top :=0; Height := 445; Width := 790; end; 5.在窗体关闭时 case UserStrToInt(Copy(caption,Length(caption),1)) of 1: begin Test1:=False; MainMDIForm.test1:=False; end; 2: begin Test2:=False; MainMDIForm.test2:=False; end; 3: begin Test3:=False; MainMDIForm.test3:=False; end; END;
你说在Form3,Form4再重新创建Form1。这是的Form1肯定不是Form2创建的Form1了。这些Form1只是同一个类(TForm1)的不同实例
如果你想在Form3,4里引用Form2创建的Form1。那么你可以把Fomr1设成全局变量,然后再Form3,4里引用Form2这个单元,这样就可以直接调用Form1了。
但是还有一点要注意:
在Form3,4并不知道Form1是否创建的时候要调用最好加上一段保护代码:
if not Assigned(Form1) then
//如果Form1没有创建的话;
else
//如果Form1没有创建了
with TForm.Create(Application) do try
ShowModal;
fianlly
Free;
end;
end;
用Delphi动态几个相同的窗体
1.先定原窗体名如:
uses Outputtest
2.在定义几个该窗体的变量
Test1Form,Test2Form,Test3Form:TOutputTestForm;
同时定义对应的几个布尔变量:
Test1,Test2,Test3:Boolean;
3.在对应的事件中加入
if not Test1 then
begin
test1Form := TOutputTestForm.Create(Application);
test1Form.Caption :='test1';
test1Form.ShowCaption(1);
end
else
Test1Form.WindowState :=wsNormal;
test1Form.show;
4.
procedure TOutputTestForm.ShowCaption(Captions: Integer);
begin
FormFlag:=Captions;
Name:='Test'+InttoStr(captions)+'Form';
case captions of
1:
begin
caption:='窗体'+InttoStr(captions);
MainMDIForm.test1:=True;
end;
2:
begin
caption:='窗体'+InttoStr(captions);
MainMDIForm.test2:=True;
end;
3:
begin
caption:='窗体'+InttoStr(captions);
MainMDIForm.test3:=True;
end;
end;
Left :=0;
Top :=0;
Height := 445;
Width := 790;
end;
5.在窗体关闭时
case UserStrToInt(Copy(caption,Length(caption),1)) of
1:
begin
Test1:=False;
MainMDIForm.test1:=False;
end;
2:
begin
Test2:=False;
MainMDIForm.test2:=False;
end;
3:
begin
Test3:=False;
MainMDIForm.test3:=False;
end;
END;