我在unit1中,定义了一个串的的变量,是在Public里面定义的,我想在unit2中使用,可是却用不了。不知道是不是对于一个工程,我的公用变量定义位置错误了,还是,有别的什么原因啊,我好郁闷!!!大家帮个忙了

解决方案 »

  1.   

    不可以的你得在UNIT1中的USES UNIT2,,然后在UNIT2中的IMP。部分  UESE UNIT1就可以了,
      

  2.   

    楼上的弟兄,谢谢你,能不能把代码贴上,在unit1中,我也说明了要引用Unit2的,可是您说的UNIT2中的IMP。部分  UESE UNIT1 我不知道在哪里,现在我在网吧,没有办法开DELPHI啊,谢谢你了,谢谢
      

  3.   

    在Implimetation的下面添加uses  Unit2;
      

  4.   

    Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation-----------:就是这个,实现部分
      

  5.   

    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
      TForm2 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        var2:string;
      end;var
      Form2: TForm2;implementation
    uses unit1;//
    {$R *.DFM}
    end.unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls,Unit2;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        var1:string;
      end;var
      Form1: TForm1;implementation{$R *.DFM}end.
      

  6.   

    只因为你定义的并非全局变量,你定义的只是窗体的成员所以要用Form2.xxx的方法引用
      

  7.   

    谢谢大家,这回我明白了,看来DELPHI的入门还要走好长的时间啊,我会经常来向前辈们请教的,:)谢谢了.今天是3.8节,祝前辈们的女朋友或则老婆节日快乐,:).thanks