Returning array using a function in Console type can be done but I am trying to make a function which takes an integer n as input and returns an array of extended in VCL form of Delphi. How can we do that?
In modern versions of Delphi you should use the generic array, TArray<T>
. Like this:
function Foo(N: Integer): TArray<Extended>;
var
i: Integer;
begin
SetLength(Result, N);
for i := 0 to N-1 do begin
Result[i] := i;
end;
end;
I would stress that it is likely a mistake to be using Extended
. This is a rather unusual and badly performing 10 byte floating point type. The type is only available on a limited number of processors. Almost all real world floating point calculations are performed using Single
or Double
, the 4 byte and 8 byte IEEE-754 floating point data types.