【发布时间】:2012-01-21 02:01:07
【问题描述】:
在询问this question about interface fields in records 之后,我认为以下方法会起作用(注意断言):
type
TRec <T> = record
Intf : IInterface;
end;
TTestClass = class
public
function ReturnRec : TRec <Integer>;
end;
// Implementation
function TTestClass.ReturnRec : TRec <Integer>;
begin
Assert (Result.Intf = nil); // Interface field in record should be initialized!
Result.Intf := TInterfacedObject.Create;
end;
我使用以下代码对此进行了测试:
for I := 1 to 1000 do
Rec := Test.ReturnRec;
断言失败!
我的错误在哪里?什么假设是错误的?
【问题讨论】:
-
断言在循环的第一次或第二次运行时是否失败?
-
@Smasher FWIW,这就是我写错误答案时的想法:stackoverflow.com/questions/5102843/…