I saw a lot of mentions of bugs in Delphi 2009 generators, but I never expected something so bad in update 3, no less. An IndexOf call for a generic TList or TObjectList causes an access violation if the list contains 1 or more elements:
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;
The exception is "EAccessViolation: Access Violation at address 0048974C in the testbed.exe module." Reading address 00000000 "
Compiling with debug DCUs results in a problem in generics.collections.pas - FComparer member is not assigned:
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;
This, of course, makes a common TList almost completely useless. Since Update 3 does not seem to have fixed this error, do I have a regression besides upgrading to XE?
source share