Results 1 to 4 of 4

Thread: natuurlijke volgorde van TDictionary

  1. #1
    John Kuiper
    Join Date
    Apr 2007
    Location
    Almere
    Posts
    8,747

    natuurlijke volgorde van TDictionary

    Ik heb iets vreemds wat ik niet kan verklaren. Ik heb het volgende stukje code:
    Delphi Code:
    1. var test   : TDictionary<integer,TMyTest>;
    2.     teller : smallint;
    3.     MyTest : TMyTest;
    4. begin
    5.   try
    6.     memo1.Lines.Clear;
    7.     randomize;
    8.     test := TDictionary<integer,TMyTest>.create;
    9.     for teller := 1 to 10 do
    10.     begin
    11.       MyTest := TMYtest.Create;
    12.       MyTest.getal := random(100);
    13.       test.Add(teller,MyTest);
    14.     end;
    15.     for teller in test.Keys do
    16.       memo1.Lines.Add(teller.ToString)
    17.   finally
    18.     test.Free;
    19.   end;
    De uitkomst is : 3 9 4 10 5 2 1 7 8 6

    Maar ik wil de natuurlijke volgorde zien van de Tdictionary zoals deze is aangegeven tijdens het toevoegen, namelijk : 1 2 3 4 5 6 7 8 9 10.

    Waarom gooit Tdictionary dit door elkaar?
    Delphi is great. Lazarus is more powerfull

  2. #2
    John Kuiper
    Join Date
    Apr 2007
    Location
    Almere
    Posts
    8,747
    Dit gaat wel goed:
    Delphi Code:
    1. var test   : TList<integer>;
    2.     teller : smallint;
    3. begin
    4.   try
    5.     memo1.Lines.Clear;
    6.     randomize;
    7.     test := TList<integer>.create;
    8.     for teller := 1 to 10 do
    9.     begin
    10.       test.Add(teller);
    11.     end;
    12.     for teller in test do
    13.       memo1.Lines.Add(teller.ToString)
    14.   finally
    15.     test.Free;
    16.   end;
    17. end;
    Zal het te maken hebben met de hash index van TDictionary?
    Delphi is great. Lazarus is more powerfull

  3. #3
    mov rax,marcov; push rax marcov's Avatar
    Join Date
    Apr 2004
    Location
    Ehv, Nl
    Posts
    10,357
    tdictionary is een hash. niet een list.

  4. #4
    TDictionary wordt gesorteerd op hash. Als je de dictionary wilt sorteren moet je een andere lijst/array gebuiken.
    zie ook:
    https://stackoverflow.com/questions/...scending-order

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •