我见过很多提及Delphi 2009中泛型的错误,但从来没有想过在Update 3中失败的基本原理,没有。在通用调用的TList的IndexOf或TObjectList导致访问冲突如果列表中包含1个或多个项目:通用TList <>在德尔福2009年崩溃在IndexOf
type
TTest = class(TObject);
procedure DoTest;
var
list : TObjectList<TTest>;
t : TTest;
begin
list := TObjectList<TTest>.Create;
try
t := TTest.Create;
list.IndexOf(t); // No items in list, correct result -1
list.Add(t);
list.IndexOf(t); // Access violation here
finally
list.Free;
end;
end;
唯一的例外是“EAccessViolation:访问冲突在模块‘testbed.exe’读地址的地址0048974C。 00000000"
与调试的DCU编译导致的问题generics.collections.pas - 在FComparer成员未分配:
function TList<T>.IndexOf(const Value: T): Integer;
var
i: Integer;
begin
for i := 0 to Count - 1 do
if FComparer.Compare(FItems[i], Value) = 0 then
Exit(i);
Result := -1;
end;
当然这使通用从TList几乎完全无用。由于Update 3似乎没有解决这个问题,除升级到XE之外,我是否有追索权?
+1,以便立即解决问题。谢谢,罗迪! – 2010-11-20 14:05:44