【发布时间】:2016-07-15 10:03:18
【问题描述】:
我在尝试移植的 Delphi Detours 库中有这段代码:
type
TInstruction = record
Archi: Byte; { CPUX32 or CPUX64 ! }
AddrMode: Byte; { Address Mode }
Addr: PByte;
VirtualAddr: PByte;
NextInst: PByte; { Pointer to the Next Instruction }
OpCode: Byte; { OpCode Value }
OpType: Byte;
OpKind: Byte;
OpTable: Byte; { tbOneByte,tbTwoByte,... }
OperandFlags: Byte;
Prefixes: Word; { Sets of Prf_xxx }
...
end;
var
Inst: TInstruction;
begin
...
Inst := default (TInstruction); // <-
Inst.Archi := CPUX;
Pvt := PPointer(AIntf)^; // vTable !
PCode := PPointer(Pvt + Offset)^; // Code Entry !
Inst.NextInst := PCode;
...
end;
“default”关键字有什么作用?
我假设类似于:
FillChar(Inst, SizeOf(TInstruction), 0);
我的假设正确吗?
【问题讨论】:
-
它也完成/初始化托管类型的字段。
-
@LURD,我可以理解“初始化”部分。但它什么时候最终确定变量?
-
@zig 例如,如果删除的记录是最后一个引用,则从动态数组和字符串中清除内存。另一个例子是取消链接
interface类型的引用计数对象。请参阅 docwiki.embarcadero.com/Libraries/XE7/en/System.Finalize -
Default在 D2009 中引入,参见:stackoverflow.com/questions/8460037/…