unit UnitloopInfo;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Data.DB, Vcl.StdCtrls,
Vcl.Grids, Vcl.DBGrids;
type
TFormloopInfo = class(TForm)
Panel1: TPanel;
DBGrid1: TDBGrid;
Label1: TLabel;
ComboBox1: TComboBox;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormloopInfo: TFormloopInfo;
deviceId:integer = -1;//在这里初始化并赋值
implementation
{$R *.dfm}
uses UnitMain,UnitDataModule;
注意:在声明时初始化的方法只适用于全局变量,这点在Delphi的代码标准文档里可以找到。
[4). 变量
(1). 局部变量
局部变量用于过程内部,果需要的话,应当在过程的入口处立即初始化变量。局部的AnsiString 类型的变量自动被初始化为空字符串,局部的接口和dispinterface类型的变量自动被初始化为nil,局部的Variant和 OleVariant类型的变量自动被初始化为Unassigned。
(2). 全局变量
一般不鼓励使用全局变量。不过,有时候需要用到。即使如此,也应当把全局变量限制在需要的环境中。例如,一个全局变量可能只在单元的实现部分是全局的。
全局数据如果将由许多单元使用,就应移动到一个公用单元里被所有对象使用。全局数据可在声明时直接初始化为一个值。注意,所有全局变量自动进行零初始化,因此,不要将全局变量初始化为诸如0 、nil、或Unassigned等空值。零初始化的全局变量在.EXE文件中不占空间。零初始化的数据保存在虚拟的数据段中,而虚拟数据段只在应用程序启动时才分配内存。非零初始化的全局数据则在.EXE文件中占空间。