那你就定义返回 record 或者 aaa(var return1...var returnN..) 做为【in/out】参数返回
例子: TYourTest=('12','123','3213'); TAssembly =Set of TYourTest; function YourFunction :TAssemBly; begin .......................... end;
先定义一个记录 TDemo = record astr1 : string; astr2 : string; end; 然后代码如下: function TForm1.setValue(var aDemo : TDemo) : Boolean; begin result := true; try aDemo.astr1 := 'astr1'; aDemo.astr2 := 'astr2'; except result := false; end; end;procedure TForm1.Button1Click(Sender: TObject); var aDemo : TDemo; begin try if setValue(aDemo) then begin Memo1.Lines.Add(aDemo.astr1); Memo1.Lines.Add(aDemo.astr2); end; except Memo1.Lines.Add('wrong'); end;end;也就是将多个返回结果放在一个记录中,作为一个变量返回。
procedure TForm1.FormButton1Click(Sender: TObject);type PMyList = ^AList; AList = record I: Integer; C: Char; end;var MyList: TList; ARecord: PMyList; B: Byte; Y: Word; begin MyList := TList.Create; try New(ARecord); ARecord^.I := 100; ARecord^.C := 'Z'; MyList.Add(ARecord); {Add integer 100 and character Z to list} New(ARecord); ARecord^.I := 200; ARecord^.C := 'X'; MyList.Add(ARecord); {Add integer 200 and character X to list} { Now paint the items onto the paintbox} Y := 10; {Variable used in TextOut function} for B := 0 to (MyList.Count - 1) do begin ARecord := MyList.Items[B]; Canvas.TextOut(10, Y, IntToStr(ARecord^.I)); {Display I} Y := Y + 30; {Increment Y Value again} Canvas.TextOut(10, Y, ARecord^.C); {Display C} Y := Y + 30; {Increment Y Value} end; { Cleanup: must free the list items as well as the list } for B := 0 to (MyList.Count - 1) do begin ARecord := MyList.Items[B]; Dispose(ARecord); end; finally MyList.Free; end; end;
var vVector:Olevariant; begin vVector:=vararraycreate([0,n],varvariant); vVector[0]:='abc'; vVector[1]:=123; vVector[2]:=1.23; . . . YourFunction(vVector); end; 明白吗?
type Txxx = packed record a : char; b : char; end;
TYourTest=('12','123','3213');
TAssembly =Set of TYourTest;
function YourFunction :TAssemBly;
begin
..........................
end;
TDemo = record
astr1 : string;
astr2 : string;
end;
然后代码如下:
function TForm1.setValue(var aDemo : TDemo) : Boolean;
begin
result := true;
try
aDemo.astr1 := 'astr1';
aDemo.astr2 := 'astr2';
except
result := false;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
aDemo : TDemo;
begin
try
if setValue(aDemo) then
begin
Memo1.Lines.Add(aDemo.astr1);
Memo1.Lines.Add(aDemo.astr2);
end;
except
Memo1.Lines.Add('wrong');
end;end;也就是将多个返回结果放在一个记录中,作为一个变量返回。
PMyList = ^AList;
AList = record
I: Integer;
C: Char;
end;var MyList: TList;
ARecord: PMyList;
B: Byte;
Y: Word;
begin
MyList := TList.Create;
try
New(ARecord);
ARecord^.I := 100;
ARecord^.C := 'Z';
MyList.Add(ARecord); {Add integer 100 and character Z to list}
New(ARecord);
ARecord^.I := 200;
ARecord^.C := 'X';
MyList.Add(ARecord); {Add integer 200 and character X to list} { Now paint the items onto the paintbox}
Y := 10; {Variable used in TextOut function} for B := 0 to (MyList.Count - 1) do
begin
ARecord := MyList.Items[B];
Canvas.TextOut(10, Y, IntToStr(ARecord^.I)); {Display I}
Y := Y + 30; {Increment Y Value again}
Canvas.TextOut(10, Y, ARecord^.C); {Display C}
Y := Y + 30; {Increment Y Value}
end; { Cleanup: must free the list items as well as the list }
for B := 0 to (MyList.Count - 1) do
begin ARecord := MyList.Items[B];
Dispose(ARecord);
end;
finally
MyList.Free;
end;
end;
vVector:Olevariant;
begin
vVector:=vararraycreate([0,n],varvariant);
vVector[0]:='abc';
vVector[1]:=123;
vVector[2]:=1.23;
.
.
.
YourFunction(vVector);
end;
明白吗?
Txxx = packed record
a : char;
b : char; end;
vVector:Olevariant;
begin
vVector:=vararraycreate([0,n],varvariant);
vVector[0]:='abc';
vVector[1]:=123;
vVector[2]:=1.23;
.
.
.
YourFunction(vVector);
FreeAndNil(vVector);
end;procedure YourFunction(aVector:OleVariant);
var
v1:String;
v2:Integer;
v3:real;
begin
v1:=aVector[0];
v2:=aVector[1];
v3:=aVector[2];
ShowMessage(format('1是''%s'',2是%d,3是%g',[v1,v2,v3]));
end;
不知道楼主是否满意?