D
DelphiVip
Unregistered / Unconfirmed
GUEST, unregistred user!
我新建一个框架, 并显示在form1->panel中. 但是有个问题, 就是我在frame1中放一个edit1控件.然后新建一个单元,一个函数;procedure getip;beginframe1.edit1.text:='123';end; 运行时, 会报错.相关代码:{---------------------------主窗体--------------------------}unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;type TMyFrame = class of TFrame; TForm1 = class(TForm) Button1: TButton; Panel1: TPanel; procedure Button1Click(Sender: TObject); private Ffrm: TFrame; FCurrentfrmClass: String; procedure LoadFrameByClassName(FrameClassName: TmyFrame); public { Public declarations } end;var Form1: TForm1;implementationuses unit2;{$R *.dfm}procedure TForm1.LoadFrameByClassName(FrameClassName:TmyFrame);begin if Assigned(Ffrm) and (not SameText(FrameClassName.ClassName,FCurrentfrmClass)) then FreeAndNil(Ffrm); Ffrm := FrameClassName.Create(nil); Ffrm.Parent := panel1; FCurrentfrmClass := FrameClassName.ClassName;end;procedure TForm1.Button1Click(Sender: TObject);beginLoadFrameByClassName(TFrame2);end;end.{--------------------框架1-Tframe1-------------------------------}unit Unit2;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,unit3;type TFrame2 = class(TFrame) Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form2:Tframe2;implementation{$R *.dfm}procedure TFrame2.Button1Click(Sender: TObject);begin getip;end;end.{-------------------------unit3----------------------------}unit Unit3;interfaceuses Windows;procedure Getip;implementationuses unit2;procedure Getip;begin form2.Edit1.Text:='123';end;end.大家可以测试, 如果写主窗体) form1.edit1.text:='123' 会正常显示(框架) form2.edit1.text:='123' 会出错. 请大家帮我修改下. 谢谢了. 100% 结