关于一个简单的FRAME(框架)问题.. 谢谢大家,我愿在追加200分..(250)

  • 主题发起人 主题发起人 DelphiVip
  • 开始时间 开始时间
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% 结
 
改成下面这样试试procedure TFrame2.Button1Click(Sender: TObject);begin unit3.getip;end;
 
依然出错.. 请各位大大帮忙调试下. 谢谢, 很简单的几个代码而已.请窗体一的代码:implementationuses unit2;把这句 uses unit2, unit2放在上面的uses里就可以调试的.
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
515
import
I
后退
顶部