Au temps pour moi, un TDictionnary ne peut être trié. Toutefois, il y a des possibilités pour en faire une lecture en ordre selon les valeurs ou les clés en passant par un Tarray
Quelque chose comme
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 uses Generics.Collections, Generics.Defaults, SysUtils; public LDict : TDictionary<integer, String>; function lettresasaisir(Adictionnary : TDictionary<Integer,String>, nombrelettres : integer) : String; var LArray : TArray<integer>; i,j : integer; begin LArray := Adictionnary.Keys.ToArray; TArray.Sort<integer>(LArray); // trier result:=EmptyStr; j:=0; for i in Larray do begin result:=result+aDictionnary.items[i]; // modifier le poids lettre aDictionnary inc(j); if j=nombrelettres then break; end; end;
Partager