我是 Delphi 的新手,我一直在运行一些测试,看看默认情况下对象变量和堆栈变量的初始化是什么:
TInstanceVariables = class
fBoolean: boolean; // always starts off as false
fInteger: integer; // always starts off as zero
fObject: TObject; // always starts off as nil
end;
这是我在其他语言中习惯的行为,但我想知道在特尔斐依赖它是否安全?例如,我想知道它是否依赖于编译器设置,或者在不同的机器上工作方式不同。依赖于对象的默认初始化值是正常的吗,还是在构造函数中显式设置所有实例变量?
As for stack (procedure-level) variables, my tests are showing that unitialized booleans are true, unitialized integers are 2129993264, and uninialized objects are just invalid pointers (i.e. not nil). I'm guessing the norm is to always set procedure-level variables before accessing them?