Ceci est une ancienne révision du document !


TList et descendants

Les Containers

Informations sur les differents types de “Containers” en Pascal.

Choisir son container

Sort

Pour utiliser la méthode Sort sur un TList il faut lui fournir une function de comparaison

unit Classes
procedure TList.Sort(Compare: TListSortCompare);
// avec
  TListSortCompare = function (Item1, Item2: Pointer): Integer;

Exemple d'implémentation.

function CompareMarkers(Item1, Item2: Pointer): integer;
var
   vQ1, vQ2: THT_Addr;
begin
   vQ1 := THO_Marker(Item1).Range.Left;
   vQ2 := THO_Marker(Item2).Range.Left;
 
   if vQ2 < vQ1 then
      Result := -1
   else
      Result := 1;
   if vQ2 = vQ1 then
      Result := 0;
end;
procedure THO_MarkerList.SortM;
begin
  Sort(@CompareMarkers);
end;

Enumeration

On en parle ici → https://www.freepascal.org/docs-html/current/rtl/system/ienumerator.html

//A for in loop like the following:
 
For O in MyObject do
  begin
  // do things
  end;
 
//is treated by the compiler as equivalent to the following code:
 
Var
  I : IEnumerator;
  O : TObject;
 
begin
  I:=MyObject.GetEnumerator;
  While I.MoveNext do
    begin
    O:=I.GetCurrent;
    // Do things
    end; 
end.

Partage de TList entre Threads

Autres listes

TList<Char>string
TList<WideChar>WideString
TList<Byte>array of Byte
TList<string>Classes.TStrings
TList<Pointer>Classes.TList
TList<Boolean>Classes.TBits
TList<TObject>Contnrs.TObjectList
TList<TComponent>Contnrs.TComponentList
TList<TClass>Contnrs.TClassList
TStack<Pointer>Contnrs.TStack
TStack<TObject>Contnrs.TObjectStack
TQueue<Pointer>Contnrs.TQueue
TQueue<TObject>Contnrs.TObjectQueue
TStream<Byte>Classes.TMemoryStream
TDictionary<TPair<string, string»Classes.TStringList
TList<TMethod>LCLProc.TMethodList
TTree<TTreeNode>ComCtrls.TTreeView
TPoint<Integer>Classes.TPoint
TPoint<SmallInt>Classes.TSmallPoint
TRectangle<Integer>Classes.TRect

Sources & Ressources

Vous pourriez laisser un commentaire si vous étiez connecté.