Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function returning an Array??

Status
Not open for further replies.

storm1

Programmer
Aug 9, 2001
6
GB
Hi there, I am new to Delphi and to this forum, and would appriciate some help.
I need a function I have written to return a dynamic array, but it doesn't seem to want to play and will only let me return a variable of type string, integer etc?
Is it possible for a function to return an array?
Sorry if this is a stupid question.
Thanks
Storm
 
Hi

You have to declare an array type for the function to return

e.g.
type arraytype = array [0..10] of integer;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);

private
function returnarray(a: integer): arraytype;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
holder: arraytype;
implementation

{$R *.DFM}
function TForm1.returnarray(a: integer): arraytype;
begin
result[a] := 3;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
holder := returnarray(1);
edit1.text := inttostr(holder[1]);
end;

Hope that helps.
Steve
 
Thanks very much, that's just what I was after.
Storm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top