这个死FRAME,花了我500分, 还没解决..大师登入啊. (9点之前回家结贴)(222)

  • 主题发起人 主题发起人 DelphiVip
  • 开始时间 开始时间
D

DelphiVip

Unregistered / Unconfirmed
GUEST, unregistred user!
流程: 新建一个窗体(FORM1),一个框价(FRAME),一个函数单元.{--------------------窗体代码---------------------}unit Window;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, pzwindow, FlatUtils, FlatPanel, jpeg, ImgList, FlatBtns;type TMyFrame = class of TFrame; TForm1 = class(TForm) TopImage: TImage; FlatPanel1: TFlatPanel; hostbt: TFlatSpeedButton; infobt: TFlatSpeedButton; wwwbt: TFlatSpeedButton; confbt: TFlatSpeedButton; shellbt: TFlatSpeedButton; mainpanel: TFlatPanel; Maindesktop: TFlatPanel; procedure hostbtClick(Sender: TObject); procedure FormCreate(Sender:TObject); private FCurrentfrmClass: String; {自身类名} Ffrm: TFrame; {mid} procedure LoadFrameByClassName(FrameClassName: TmyFrame); {加载类窗体} public { Public declarations } end;var Form1: TForm1;implementation{$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 := mainDesktop; FCurrentfrmClass := FrameClassName.ClassName;end;{窗体创建过程}procedure TForm1.FormCreate(Sender:TObject);begin FCurrentfrmClass := '';end;procedure TForm1.hostbtClick(Sender: TObject);beginLoadFrameByClassName(Tframe2);end;end.{-------------------------------------------------}{-------------------框价代码----------------------}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;implementation{$R *.dfm}procedure TFrame2.Button1Click(Sender: TObject);var ID:Thandle; Ip:string;beginCreateThread(nil, 0, @Get, nil, 0, ID);end;end.{------------------------------------------------}{----------------------函数单元------------------}unit Unit3;interfaceuses windows;procedure Get;implementationuses unit2;procedure Get;var Gframe:TFrame2; { 这句是这样声明的吗? }begin Gframe.Edit1.Text:='123';end;end.{------------------------------------------------------------}如果不采用多线程, 程序不出错 .. 而且那个声明Gframe:TFrame2;,我总觉的有问题.有时不采用线程, 就一个函数, 也会报错..报错图片:
20090828183842_rednet.jpg
 
{-------------------框价代码----------------------}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 Frame2:TFrame2 procedure TFrame2.Button1Click(Sender: TObject);var ID:Thandle; Ip:string;beginCreateThread(nil, 0, @Get, nil, 0, ID);end;end.{--------------------窗体代码---------------------}procedure TForm1.FormCreate(Sender:TObject);begin Frame2:=TFrame2.Create(nil);end;procedure TForm1.hostbtClick(Sender: TObject);begin Frame2.Parent := mainDesktop;end;{----------------------函数单元------------------}procedure Get;begin Frame2.edit1.text:='123';end;
 
您好, 大师. 我按照你的改的, 把原来窗体代码全部替换为:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, unit2;type TForm1 = class(TForm) Button1: TButton; Panel1: TPanel; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);begin Gframe:=TFrame2.Create(nil);end;procedure TForm1.Button1Click(Sender: TObject);begin Gframe.Parent := panel1; [red]到这句出现调试错误.[/red]end;end.
 
测试没问题啊。unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,Unit2, StdCtrls, ExtCtrls;type TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);begin Frame2.Parent := panel1;end;procedure TForm1.FormCreate(Sender: TObject);begin Frame2:=TFrame2.Create(nil);end;end.------------------------------unit Unit2;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TFrame2 = class(TFrame) Edit1: TEdit; private { Private declarations } public { Public declarations } end;var Frame2:TFrame2;implementation{$R *.dfm}end.
 
谢谢大师, 终于通过了.. 谢谢, 我爱你..
 
(*你到底想干嘛呀?你自己看看GET中的那个GFRAME变量是否初始化了,到底引用 了什么东西呢?....*)
 
后退
顶部