按你的意思大概应该这样做:
1、先New一个Unit,在interface部分声明的全局变量:
unit Unit2;
interface
var
aa:integer;//你的全局变量定义在这里
implementation
end.
2、在你要使用这个全局变量的单元是Use上面的单元:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;//引用刚才新建的单元
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
aa:=2;//直接使用全局变量
caption:=inttostr(aa);
end;
end.