unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
/////////////////////////////
//在 implementation上定义的全局变量在所有单元可见
var teststr:string;
implementation
{$R *.dfm}
//////////////////////////////
//在implementation下定义的只对本单元可见
var teststr1:string;
procedure TForm1.Button1Click(Sender: TObject);
begin
//////////////////////
//对teststr赋值
teststr := '我是对所有单元都可见的';
showmessage(teststr);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
/////////////////////
//对teststr11赋值
teststr1 := '我只对本单元可见';
showmessage(teststr1);
end;
end.