C
chenxu_sichuan
Unregistered / Unconfirmed
GUEST, unregistred user!
如果我在program中声明了一个全局变量,如何在其他Unit中调用?代码如下:
//program的源代码:
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.RES}
//这是我声明的变量
var
a:AnsiString;
begin
Application.Initialize;
a := 'test';
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
//调用此全局变量的Unit源代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
//调用在program中声明的全局变量a ,但是编译通不过,在BCB中是可以的!
ShowMessage(a);
end;
end.
//program的源代码:
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.RES}
//这是我声明的变量
var
a:AnsiString;
begin
Application.Initialize;
a := 'test';
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
//调用此全局变量的Unit源代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
//调用在program中声明的全局变量a ,但是编译通不过,在BCB中是可以的!
ShowMessage(a);
end;
end.