[fpc-pascal] TArray.Sort<string>(array) returns 'Error: Identifier not found "TArray" '

silvioprog silvioprog at gmail.com
Thu Aug 4 03:16:56 CEST 2016


Hello,

First, thanks a lot for the rtl-generics units, this really was a
great contribution to the Free Pascal community!

So, sometimes, I need to sort the values of a specialized key/value list,
but I can't compile the adapted Delphi XE code below (I'm using MODE
DELPHI):

=== begin code ===

var
  key: string;
  ordkeys: TArray<string>;
  list: TDictionary<string, string>;
begin
  list := TDictionary<string, string>.Create;
  try
    list.Add('a', 'aaa');
    list.Add('b', 'bbb');
    list.Add('c', 'ccc');
    ordkeys := list.Keys.ToArray;
    TArray.Sort<string>(ordkeys);
    for key in ordkeys do
      WriteLn(key, ' - ', list[key]);
  finally
    list.Free;
  end;
end.

=== end code ===

I got:

'Error: Identifier not found "TArray"'

So I've fixed it with:

=== begin code ===

...

{$IFDEF FPC}
    TArrayHelper<string>.Sort(ordkeys);
{$ELSE}
    TArray.Sort<string>(ordkeys);
{$ENDIF}

...

=== end code ===

So, is this the best way to solve this problem?

Thank you!

P.S.: You should remove the {$H+} from the generics.* units, the mode
Delphi already enables the long strings
<http://www.freepascal.org/docs-html/prog/progsu25.html>.

-- 
Silvio Clécio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160803/f7eebcf5/attachment.html>


More information about the fpc-pascal mailing list