1

I need to sort a TArray<integer>, I've added System.Generics.Collections to the uses clause and then I've tried the following code:

var
  Arr : TArray<integer>;
begin
  SetLength(Arr, 2);
  Arr[0] := 5;
  Arr[1] := 3;

  TArray.Sort(Arr);

  ShowMessage(IntToStr(Arr[0]));
end;

On compiling it produces an E2250 error saying:

[dcc32 Error] Unit1.pas(39): E2250 There is no overloaded version of 'Sort' that can be called with these arguments

1 Answer 1

3

While writing the question I've found the answer... (It was a trivial syntax problem)

In TArray class, the Sort function is defined as follows:

class procedure Sort<T>(var Values: array of T); overload; static;

So TArray class functions must be called by specifying the type after the function name:

var
  Arr : TArray<integer>;
begin
  SetLength(Arr, 2);
  Arr[0] := 5;
  Arr[1] := 3;

  TArray.Sort<integer>(Arr);

  ShowMessage(IntToStr(Arr[0]));
end;
Sign up to request clarification or add additional context in comments.

1 Comment

A decent compiler would be able to infer the type. Delphi generics though, meh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.