問一個FORM 之間傳全局变量的問題 , 全局变量為什麼不可見呢?? 那你这个变量一定是写在TForm2的类里面了,而访问的时候还没有创建TForm2的对象实例,如form2:=Tform2.create(application),就去访问这个写在类离的变量,就会出现地质访问错误之类的错误. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 access violation 错误一般来说是引用的对象没有创建,或者已经被释放了。 单元中的全局变量声明:unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var //单元中的全局变量声明处 Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);beginend;end. 单元中的全局变量声明:unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var //单元中的全局变量声明处 Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);beginend;end. 为什莫搞得这莫复杂啊。既然是全局变量,将其定义在任意一个不是动态创建的Form的借口部分,其他Form uses这个单元就好了! 你的form2不能关闭变量名前面还要加form2.变量名 你的访问代码最好不要放在FormCreate里面 type TfTrainBBS = class(TForm) TVBBS: TTreeView; procedure TVBBSDblClick(Sender: TObject); private { Private declarations } public { Public declarations } end;var fTrainBBS: TfTrainBBS; data: array of array of Int64; //form2中這麼定義;procedure TfTrainMain.Button3Click(Sender: TObject);var TrainBBS : TfTrainBBS;begin TrainBBS := TfTrainBBS .Create(Application); //調用form3 TrainBBS.Show;end; taidy() 說的方法我想過,好像也不行. to sogh(青山之音) : 為什麼 '你的访问代码最好不要放在FormCreate里面'??? 我没有详细看代码,不过我以前也遇到这种问题1你的form2是动态创建的吧,当你调用出form3的时候,你的form2已经释放了,所以地址访问未归!!! to sogh(青山之音) : 為什麼 '你的访问代码最好不要放在FormCreate里面'??? 大家可以試試嘛.form1點一個button調用form2,form2點一個button調用form3 form2定義變量,form3使用. 你的程序没有公共的函数单元吗?放那里面,再USE就行了 你是全局变量?Unit Unit1...Var Form1 : TForm1; ...//定义 可能犯的是一些低级错误你检查检查 是否在如TForm2中使用Form2变量什么的另外正如zbpro所建议最好使用独立的一个单元来声明全局变量、函数及类型//我的工程用了两个!主要保存通用函数的单元//FunctionUnit.pas//如:字符串的处理函数等主要保存全局资源的单元//PublicUnit.pas//如:用户登录的信息、软件版本信息等所有的窗体单元都要uses她们 file->new->unit把函数写在这个新的单元中! 可能犯的是一些低级错误你检查检查 是否在如TForm2中使用Form2变量什么的另外正如zbpro所建议最好使用独立的一个单元来声明全局变量、函数及类型//我的工程用了两个!主要保存通用函数的单元//FunctionUnit.pas//如:字符串的处理函数等主要保存全局资源的单元//PublicUnit.pas//如:用户登录的信息、软件版本信息等所有的窗体单元都要uses她们 低级错误; 注釋掉下面2行就行了.program PHumtrainPub;uses Forms, uTrainMain in 'uTrainMain.pas' {fTrainMain}, udmTrainPub in 'udmTrainPub.pas' {DM2: TDataModule}; //uBBSView in 'uBBSView.pas' {fTrainBBSView};{$R *.RES}begin Application.Initialize; Application.CreateForm(TfTrainMain, fTrainMain); //Application.CreateForm(TfTrainBBSView, fTrainBBSView); Application.CreateForm(TDM2, DM2); Application.Run;end. BHO的问题 如何遍历treeview的第一级根结点? PowerDesigner 的问题:能不能或者如何实现表结构同步而不丢失数据? 如何在AdvStringGrid中为每个单元格内的字体定制颜色 有一个传递地址参数的问题,急急急!!!!! 问一个关于类的问题!!! treeview Delphi 2007 无法启动 delphi文件读取与写入问题 如何动态讲网络运行情况简单显示在一个节点分布图上 急!请问用DELPHI如何实现网格单元的超链接? 关于数据库
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
//单元中的全局变量声明处
Form1: TForm1;
implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
beginend;end.
unit Unit1;
interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
//单元中的全局变量声明处
Form1: TForm1;
implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
beginend;end.
变量名前面还要加form2.变量名
TfTrainBBS = class(TForm)
TVBBS: TTreeView; procedure TVBBSDblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
fTrainBBS: TfTrainBBS;
data: array of array of Int64; //form2中這麼定義;
procedure TfTrainMain.Button3Click(Sender: TObject);
var
TrainBBS : TfTrainBBS;
begin
TrainBBS := TfTrainBBS .Create(Application); //調用form3
TrainBBS.Show;end;
taidy() 說的方法我想過,好像也不行.
為什麼 '你的访问代码最好不要放在FormCreate里面'???
你的form2是动态创建的吧,当你调用出form3的时候,你的form2已经释放了,所以地址访问未归!!!
為什麼 '你的访问代码最好不要放在FormCreate里面'???
form1點一個button調用form2,form2點一個button調用form3
form2定義變量,form3使用.
Unit Unit1
...
Var
Form1 : TForm1;
...//定义
你检查检查 是否在如TForm2中使用Form2变量什么的
另外正如zbpro所建议
最好使用独立的一个单元来声明全局变量、函数及类型//我的工程用了两个!
主要保存通用函数的单元//FunctionUnit.pas//如:字符串的处理函数等
主要保存全局资源的单元//PublicUnit.pas//如:用户登录的信息、软件版本信息等
所有的窗体单元都要uses她们
把函数写在这个新的单元中!
你检查检查 是否在如TForm2中使用Form2变量什么的
另外正如zbpro所建议
最好使用独立的一个单元来声明全局变量、函数及类型//我的工程用了两个!
主要保存通用函数的单元//FunctionUnit.pas//如:字符串的处理函数等
主要保存全局资源的单元//PublicUnit.pas//如:用户登录的信息、软件版本信息等
所有的窗体单元都要uses她们
Forms,
uTrainMain in 'uTrainMain.pas' {fTrainMain},
udmTrainPub in 'udmTrainPub.pas' {DM2: TDataModule};
//uBBSView in 'uBBSView.pas' {fTrainBBSView};{$R *.RES}begin
Application.Initialize;
Application.CreateForm(TfTrainMain, fTrainMain);
//Application.CreateForm(TfTrainBBSView, fTrainBBSView);
Application.CreateForm(TDM2, DM2);
Application.Run;end.