给你个例子
server:
procedure TRemoteServer.GetRecord_TB_JCWH_DCDW(var vtable: OleVariant);
var
// m : Integer;
nRecords, nColumns, nCurRec : Integer;
str: string;
begin
//***********查询数据库得到建树的结果集*******
str:='select dcid,dcmc from tb_jcwh_dcdw order by dcid';
query3.close;
query3.sql.Clear;
query3.sql.Add(str);
try
query3.open;
except
exit;
end;
//************************************************
nRecords := -1;
nColumns := -1;
try
{ 生成数组... }
{ 大小为 0..m-1 , m 等于行数. }
nColumns := Max(0, 1);
{ 每一元素是大小 (0..n) 的数组,n 等于记录数 }
{ 第0个元素存贮显示字段名. }
nRecords := Max(0, query3.RecordCount-1);
vtable := VarArrayCreate([0, nColumns, 0, nRecords],
varVariant);
//for m := 0 to nColumnsdo
// vtable[m, 0] := query3.Fields[m].DisplayLabel;
query3.First;
nCurRec := 0;
{ nCurRec记录当前记录号. }
while not query3.Eofdo
begin
{ 赋字段值. }
vtable[0, nCurRec] := query3.Fieldbyname('dcid').asstring;
vtable[1, nCurRec] := query3.Fieldbyname('dcmc').asstring;
query3.Next;
Inc(nCurRec);
end;
except
on E: Exceptiondo
raise Exception.Create('CreateVarArrayFromDataset() - ' +
IntToStr(nRecords) +
' rec,'+IntToStr(nColumns)
+'cols,'+E.Message);
end;
end;
client:
//**************建电厂名称框***********
procedure Tqx_xqss_main.FormCreate(Sender: TObject);
var Ldata:Tdata;
dataquery
levariant;
j : integer;
i : integer;
begin
try
DCOMConnection1.Connected := true;
except
showmessage('数据库连接错误');
exit;
end;
//得到建树结果集
DCOMConnection1.AppServer.GetRecord_TB_JCWH_DCDW(dataquery);
if varisarray(dataquery) then
begin
i := vararrayhighbound(dataquery,2);
end
else
exit;
ldata := nil;
j := 0;
while (j <= i)do
begin
try
Ldata:=Tdata.Create;
except
exit;
end;
Ldata.dcid:=dataquery[0,j];
CbX_dcmc.Items.AddObject(dataquery[1,j],Ldata);
inc(j);
end;
if CbX_dcmc.Items.Count < 1 then
begin
FCurrentDcid:='';
exit;
end;
CbX_dcmc.ItemIndex:=0;
FCurrentDcid:=TData(CbX_dcmc.Items.Objects[CbX_dcmc.ItemIndex]).dcid;
end;
//**************************************