相关疑难解决方法(0)

在Delphi中初始化哪些变量?

所以我总是听说类字段(基于堆)被初始化,但基于堆栈的变量不是.我还听说记录成员(也是基于堆栈的)也没有初始化.编译器警告局部变量未初始化([DCC警告] W1036变量'x'可能尚未初始化),但不会对记录成员发出警告.所以我决定进行测试.

对于所有记录成员,我总是从Integers得到0而从布尔都得到.

我尝试打开和关闭各种编译器选项(调试,优化等),但没有区别.我的所有记录成员都正在初始化.

我错过了什么?我正在使用Delphi 2009 Update 2.

program TestInitialization;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  TR = Record
  Public
    i1, i2, i3, i4, i5: Integer;
    a: array[0..10] of Integer;
    b1, b2, b3, b4, b5: Boolean;
    s: String;
  End;

var
  r: TR;
  x: Integer;

begin
  try
    WriteLn('Testing record. . . .');
    WriteLn('i1 ',R.i1);
    WriteLn('i2 ',R.i2);
    WriteLn('i3 ',R.i3);
    WriteLn('i4 ',R.i4);
    WriteLn('i5 ',R.i5);

    Writeln('S ',R.s);

    Writeln('Booleans: ', R.b1, ' ', R.b2, ' ', R.b3, ' …
Run Code Online (Sandbox Code Playgroud)

delphi variables initialization delphi-2009

32
推荐指数
2
解决办法
8540
查看次数

标签 统计

delphi ×1

delphi-2009 ×1

initialization ×1

variables ×1