type TArr = array of integer;function abc(a:integer):Tarr; var tempArr:TArr; begin setlength(tempArr,2); tempArr[0] := a; tempArr[1] := a + 10; result:=tempArr; end;procedure TForm1.Button1Click(Sender: TObject); var a : integer; begin a := 5; showmessage(inttostr( abc(a)[0] )); //5 //这以这样使用返回数组 showmessage(inttostr( abc(a)[1] )); //15 //这以这样使用返回数组 end;
delphi 7支持对象数组吗? ------------------------- 支持。上面所说的,都是“简单类型”的“对象”的数组。 以下是一个按钮数组。只是演示用。var I : integer; BtnArr : array[1..5] of TButton; begin for I := Low(BtnArr) to High(BtnArr) do begin BtnArr[I] := TButton.Create(self); BtnArr[I].Parent := self; BtnArr[I].Name := 'Btn'+IntToStr(I); BtnArr[I].Left := 50; BtnArr[I].Top := I * 50; BtnArr[I].Width := 50; BtnArr[I].Height := 20; BtnArr[I].Show; end; end;
Tintarr=array [0..100] of integer;function FunA():tintarr;
其实更推荐这种操作:
function FunB(var aintarr:Tintarr):integer;
var
IntArr:TIntArr;
funb(intarr);
myArray=array of integer;/////////
function getArray():myArray;
begin
............
end;
TArr = array of integer;function abc(a:integer):Tarr;
var
tempArr:TArr;
begin
setlength(tempArr,2);
tempArr[0] := a;
tempArr[1] := a + 10;
result:=tempArr;
end;procedure TForm1.Button1Click(Sender: TObject);
var
a : integer;
begin
a := 5;
showmessage(inttostr( abc(a)[0] )); //5 //这以这样使用返回数组
showmessage(inttostr( abc(a)[1] )); //15 //这以这样使用返回数组
end;
-------------------------
支持。上面所说的,都是“简单类型”的“对象”的数组。
以下是一个按钮数组。只是演示用。var
I : integer;
BtnArr : array[1..5] of TButton;
begin
for I := Low(BtnArr) to High(BtnArr) do
begin
BtnArr[I] := TButton.Create(self);
BtnArr[I].Parent := self;
BtnArr[I].Name := 'Btn'+IntToStr(I);
BtnArr[I].Left := 50;
BtnArr[I].Top := I * 50;
BtnArr[I].Width := 50;
BtnArr[I].Height := 20;
BtnArr[I].Show;
end;
end;