====== TList et descendants ====== ===== Les Containers ===== Informations sur les differents types de "Containers" en Pascal. * [[https://wiki.freepascal.org/Data_Structures,_Containers,_Collections/fr|Data Structures, Containers, Collections/fr]] * [[https://www.freepascal.org/docs-html/current/rtl/classes/tfplist.html|TFPList]] ==== Choisir son container ==== * ''TFPList'' VS ''TStringList'' : il vaudrait mieux utiliser ''TStringList'' d'aprés [[https://www.freepascal.org/docs-html/current/rtl/classes/tfplist.html|les informations contenues sur cette page]] ===== Sort ===== Pour utiliser la méthode Sort sur un TList il faut lui fournir une function de comparaison 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 ===== avec TThreadList -> [[https://www.freepascal.org/docs-html/rtl/classes/tthreadlist.html]] ===== Autres listes ===== |TList|string| |TList|WideString| |TList|array of Byte| |TList|Classes.TStrings| |TList|Classes.TList| |TList|Classes.TBits| |TList|Contnrs.TObjectList| |TList|Contnrs.TComponentList| |TList|Contnrs.TClassList| |TStack|Contnrs.TStack| |TStack|Contnrs.TObjectStack| |TQueue|Contnrs.TQueue| |TQueue|Contnrs.TObjectQueue| |TStream|Classes.TMemoryStream| |TDictionary>|Classes.TStringList| |TList|LCLProc.TMethodList| |TTree|ComCtrls.TTreeView| |TPoint|Classes.TPoint| |TPoint|Classes.TSmallPoint| |TRectangle|Classes.TRect| ====== Sources & Ressources ====== * [[http://www.atug.com/andypatterns/collections.htm|TCollection VS TList VS TObjectList]] * [[https://stackoverflow.com/questions/5797368/delphi-tlist-of-records|TList Of Records]] : Utilisation d'un ''TList'' a la place d'un ''Array'' ou ''Dynamic Array'' pour contenir des ''Records''. * [[https://wiki.freepascal.org/Templates/fr|les templates -> TList]] * [[https://wiki.freepascal.org/Data_Structures,_Containers,_Collections/fr|Data Structures, Containers, Collections]]