問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;
和斷言失敗!
哪裏是我的錯嗎?什麼假設是錯誤的?
是否斷言失敗環路的第一或第二次運行? – Johan 2011-12-15 11:52:56
@Smasher FWIW,這就是我在想,如果我寫我的不正確的答案的:http://stackoverflow.com/questions/5102843/delphi-function-result-not-emptied-during-for-loop – 2011-12-15 13:14:05