Recent

Author Topic: Sorting TStringArray with keys from TFPGMap  (Read 1030 times)

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Sorting TStringArray with keys from TFPGMap
« on: July 09, 2020, 12:34:19 pm »
In Delphi I use this line of code to sort a TDictionary
Code: Pascal  [Select][+][-]
  1. var    sortedDictKeys : TList<string>;
  2. begin
  3.   sortedDictKeys := TList<string>.Create(flink.CellInhoud.Keys); //TDictionary
  4.   sortedDictKeys.Sort;
  5. end;
  6.  
I converted my project to lazarus. This is my converted code:
Code: Pascal  [Select][+][-]
  1. var    sortedDictKeys : TStringArray;
  2. begin
  3.   sortedDictKeys := TStringArray.Create(flink.CellInhoud.Keys); //TFPGMap
  4.   sortedDictKeys.Sort;
  5. end;
  6.  
flink.CellInhoud is a TFPGMap structure. I want to get all keyvalues to TStringarray, but keys needs a parameter to read. How do I read all keys at once.

TStringArray doesn't sort.
Which option do I need to sort a single line of array in my case?

I don't want to sort TFPGMap, because it not sorting on name, but on pointer.

Lazarus 2.06 / FPC 3.04
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Sorting TStringArray with keys from TFPGMap
« Reply #1 on: July 09, 2020, 01:21:32 pm »
You can use Generics.Collections in FPC as well. For 3.0.4 you can download it here, for 3.2 and newer its integrated into the distribution.

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Sorting TStringArray with keys from TFPGMap
« Reply #2 on: July 09, 2020, 01:50:43 pm »
Yes, I know. But is there also a solution for fgl?
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Sorting TStringArray with keys from TFPGMap
« Reply #3 on: July 09, 2020, 04:35:45 pm »
You need to assign a OnKeyCompare event handler.

 

TinyPortal © 2005-2018