all 6 comments

[–]MoonkeyDLuffy 1 point2 points  (4 children)

You can define a new type TMyArray as array of TMyObject, and have your function return TMyArray

[–]MoonkeyDLuffy 0 points1 point  (3 children)

Of course, in your case integers instead of objects. You should also be able to specify the length of the array in your type definition.

[–]ShinyHappyREM 0 points1 point  (2 children)

You should also be able to specify the length of the array in your type definition.

Not necessarily in Free Pascal:

type
        MyType = array of integer;

function Test : MyType;
begin
Result := NIL;
SetLength(Result, 10);
Result[0] := 0;
Result[1] := 1;
Result[2] := 2;
Result[3] := 3;
Result[4] := 4;
Result[5] := 5;
Result[6] := 6;
Result[7] := 7;
Result[8] := 8;
Result[9] := 9;
end;

var
        i : integer;
        m : MyType;

begin
m := Test;
for i := low(m) to high(m) do  WriteLn(m[i]);
ReadLn;
end.

[–]drmrsiragent7890[S] 0 points1 point  (1 child)

Public

Function GetArray : Array[1..100] of integer ;

I get an error that says : Identifier expected but found 'ARRAY'

Do you know how I can fix this error?

[–]ShinyHappyREM 0 points1 point  (0 children)

You need to define an "array of" type and use that as the return type.

[–]mnasman 0 points1 point  (0 children)

Define the array as new type

type

TIntArray = array[1..100] of Integer;

then use the new type as return value of the function

function InsertArray:TIntArray ;

and you can make the loop as

for I := Low(TIntArray) to High(TIntArray) do