那你这个变量一定是写在TForm2的类里面了,而访问的时候还没有创建TForm2的对象实例,如form2:=Tform2.create(application),就去访问这个写在类离的变量,就会出现地质访问错误之类的错误.

解决方案 »

  1.   

    access violation 错误一般来说是引用的对象没有创建,或者已经被释放了。
      

  2.   

    单元中的全局变量声明:
    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.
      

  3.   

    单元中的全局变量声明:
    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.
      

  4.   

    为什莫搞得这莫复杂啊。既然是全局变量,将其定义在任意一个不是动态创建的Form的借口部分,其他Form uses这个单元就好了!
      

  5.   

    你的form2不能关闭
    变量名前面还要加form2.变量名
      

  6.   

    你的访问代码最好不要放在FormCreate里面
      

  7.   

    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() 說的方法我想過,好像也不行.
      

  8.   

    to  sogh(青山之音) :
        為什麼  '你的访问代码最好不要放在FormCreate里面'???
      

  9.   

    我没有详细看代码,不过我以前也遇到这种问题1
    你的form2是动态创建的吧,当你调用出form3的时候,你的form2已经释放了,所以地址访问未归!!!
      

  10.   

    to  sogh(青山之音) :
        為什麼  '你的访问代码最好不要放在FormCreate里面'???
      

  11.   

    大家可以試試嘛.
    form1點一個button調用form2,form2點一個button調用form3
     form2定義變量,form3使用.
      

  12.   

    你的程序没有公共的函数单元吗?放那里面,再USE就行了
      

  13.   

    你是全局变量?
    Unit Unit1
    ...
    Var
      Form1 : TForm1;
      ...//定义
      

  14.   

    可能犯的是一些低级错误
    你检查检查 是否在如TForm2中使用Form2变量什么的
    另外正如zbpro所建议
    最好使用独立的一个单元来声明全局变量、函数及类型//我的工程用了两个!
    主要保存通用函数的单元//FunctionUnit.pas//如:字符串的处理函数等
    主要保存全局资源的单元//PublicUnit.pas//如:用户登录的信息、软件版本信息等
    所有的窗体单元都要uses她们
      

  15.   

    file->new->unit
    把函数写在这个新的单元中!
      

  16.   

    可能犯的是一些低级错误
    你检查检查 是否在如TForm2中使用Form2变量什么的
    另外正如zbpro所建议
    最好使用独立的一个单元来声明全局变量、函数及类型//我的工程用了两个!
    主要保存通用函数的单元//FunctionUnit.pas//如:字符串的处理函数等
    主要保存全局资源的单元//PublicUnit.pas//如:用户登录的信息、软件版本信息等
    所有的窗体单元都要uses她们
      

  17.   

    低级错误;     注釋掉下面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.