Informations sur les differents types de “Containers” en Pascal.
TFPList VS TStringList : il vaudrait mieux utiliser TStringList d'aprés les informations contenues sur cette pagePour 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;
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.
avec TThreadList → https://www.freepascal.org/docs-html/rtl/classes/tthreadlist.html
| 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 |
TList a la place d'un Array ou Dynamic Array pour contenir des Records.