Skip to content

Making GetPointerEnumerator available in TList class

Summary

For TList instances that store records, TList.GetEnumerator.GetCurrent returns a deep copy of the content. For certain usecases, like the one described in the one discussed in this thread, having a pointer to the content of the list would make sense.

Example Project

type
  TMyRecord = record
    Str: AnsiString;
    Index: Integer;

  end;

  TMyList = specialize TList<TMyRecord>;

function Check1(const MyList: TMyList): Integer;
var
   it: TMyList.TPointersEnumerator;

begin
  Result := 0;
  it := MyList.GetPtrEnumerator;

  while it.MoveNext do
    if it.Current.Index mod 100 = 0 then
      Inc(Result);

end;
Edited by Amir Aavani
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information