delphi5中的全局integer数组是否系统会自动初始化为0 会的.一般在implement的后面就可以了. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 全局变量一般在哪里定义implement的前后都可 可以。如在一个unit中,implement的后面就可以了,如在一个project中,定义在implement的前面(Interface之后)。 在implement的前面定义的可以被其他单元所引用/修改.在implement的后面定义的只可以被该单元使用. 全局变量在interface之后implementation之前定义。例如:unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;var TestInt1: Integer;//全局变量type TForm1 = class(TForm) private { Private declarations } public { Public declarations } end;var Form1: TForm1;//全局变量 TestInt2: Integer;//全局变量implementation{$R *.DFM}end. 是的,全局数组亦被初始化为零还有 implementation 后定义的变量也算是全局变量(狭义的)相对过程内的局部变量而言 做了个试验,发现interface 后定义的全局数组不能完全初始化为0 to snowrain(雪雨) 我做的测试如下:unit Unit1;interfaceuses 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; gdAry: array[0..99]of integer;implementationvar a, b: integer; c, d: Double; ingdAry: array[0..99]of integer;{$R *.DFM} function SumIntArray(ary: array of Integer): Integer; var I: integer; begin Result := 0; for i:=Low(ary) to High(ary) do Result := Result + ary[i]; end;procedure TForm1.Button1Click(Sender: TObject);var lcAry: array[0..50]of integer; msg: string;begin msg := 'before implementation sum value:' + IntToStr(SumIntArray(gdAry)) + #13#10; msg := msg + 'in implementation sum value:' + IntToStr(SumIntArray(ingdAry)) + #13#10; msg := msg + 'Locate sum value:' + IntToStr(SumIntArray(lcAry)) + #13#10; showmessage(msg);end;end. 全局数组肯定被初始化为零,但局部数组不会。implementation 前的全局数组外部Unit也可以引用,implementation 后的全局数组外部Unit不可以引用。定义了全局数组的Unit中的类最好不要在一个Application中出现多了实例,否则会导致不确定值。 在詷用前设个断点,用F4运行,把MOUSE移到哪个变量上,就会出现变量的大小,哪就知是不是.了。 bsToolWindow风格的窗格在拖拉的时候会被任务栏遮住 感慨:非专业程序员的生存之道. 新年好,给delphi的兄弟拜年了 与高手探讨一个异常处理的问题,如果回答满意,还可以加分 关于ADO的问题,在线等待........ 怎么样才能让button控件显示hint? 请问怎样获得本机的IP地址?:) DCOM问题,我就这点分了,全给你们 DELPHI如何生成一段时间内的所有日期的数组,谢谢! 一个普遍问题(非技术性) 怎样屏蔽Tprinter跳行?谢谢各位大虾~~ 哪儿可以找到汉化后的delphi帮助系统,或部分汉化?我想汉化delphi的帮助系统,请大家提供帮助啊
如在一个unit中,implement的后面就可以了,如在一个project中,定义在implement的前面(Interface之后)。
在implement的后面定义的只可以被该单元使用.
例如:unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;var
TestInt1: Integer;//全局变量type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;//全局变量
TestInt2: Integer;//全局变量implementation{$R *.DFM}end.
unit Unit1;interfaceuses
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;
gdAry: array[0..99]of integer;implementationvar
a, b: integer;
c, d: Double;
ingdAry: array[0..99]of integer;{$R *.DFM} function SumIntArray(ary: array of Integer): Integer;
var I: integer;
begin
Result := 0;
for i:=Low(ary) to High(ary) do
Result := Result + ary[i];
end;procedure TForm1.Button1Click(Sender: TObject);
var
lcAry: array[0..50]of integer;
msg: string;
begin
msg := 'before implementation sum value:' + IntToStr(SumIntArray(gdAry)) +
#13#10;
msg := msg + 'in implementation sum value:' + IntToStr(SumIntArray(ingdAry)) +
#13#10;
msg := msg + 'Locate sum value:' + IntToStr(SumIntArray(lcAry)) +
#13#10;
showmessage(msg);
end;end.
但局部数组不会。implementation 前的全局数组外部Unit也可以引用,
implementation 后的全局数组外部Unit不可以引用。定义了全局数组的Unit中的类最好不要在一个Application中出现多了实例,
否则会导致不确定值。