Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-08

TArray.Sort<string>(array) returns 'Error: Identifier not found "TArray" '

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

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
Sven Barth
to silvioprog
"silvioprog" wrote 21 lines
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?

For now, yes. Maciej still needs to adjust the code to make use of the features added in trunk.

P.S.: You should remove the {$H+} from the generics.* units, the mode

Delphi already enables the long strings.

It might be redundant, but it doesn't hurt either.

Regards,
Sven

Maciej Izak
to silvioprog: First, thanks a lot for the rtl-generics units, this really was a great contribution to…

2016-08-04 3:16 GMT+02:00 silvioprog :

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

TArrayHelper is marked as experimental structure and exist only temporary for bug workaround (see page 1 of
https://github.com/dathox/generics.collections/blob/master/GenericsCompatibilityMatrix.pdf).

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>.

That will be probably removed ;)

Best regards, Maciej Izak
silvioprog
to Maciej Izak: 2016-08-04 3:16 GMT+02:00 silvioprog : TArrayHelper is marked as experimental structure…
"Maciej Izak" wrote 6 lines
2016-08-04 3:16 GMT+02:00 silvioprog : > > So, is this the best way to solve this problem? TArrayHelper is marked as experimental structure and exist only temporary

for bug workaround (see page 1 of
https://github.com/dathox/generics.collections/blob/master/GenericsCompatibilityMatrix.pdf ).

Awesome.

Will you keep the sparta-generics package at Lazarus sources?

Thanks for sharing the PDF, it will help me a lot to migrate my code from FGL to Generics.Collections.

Silvio Clecio
Maciej Izak
to silvioprog

2016-08-08 4:09 GMT+02:00 silvioprog :

Will you keep the sparta-generics package at Lazarus sources?

Probably yes. sparta_Generics package exist because FPC 3.0 does not contain Generics.*...

Best regards, Maciej Izak