delphi工程中如何定义全局变量

来源:百度知道 编辑:UC知道 时间:2024/05/13 15:31:41
delphi工程中如何定义全局变量
如何在一个工程中使得不同的pas文件共享一个pas文件中定义的全局变量

新建一个公用单元,专门放置公用全局变量呗
unit untCommon;

interface

var
v1:integer;
v2:string;

end.
-----------------
unit unit1;

interface

uses
windows, ................, untCommon ; //在每个需要使用v1、v2变量的单元中引用上面那个单元untCommon就可以了

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
GlobalVar: String; //全局的在这定义,其他单元用这个变量只需uses 一下本单元就可以了

implementation

{$R *.dfm}

end.