看看对你有帮助吗?
将Datasets的数据DCOM方式传递
procedure CreateVarArrayFromDataset(var varResultSet: OleVariant;
ADataset : TDataset);
var
m : Integer;
nRecords, nColumns, nCurRec : Integer;
begin
nRecords := -1;
nColumns := -1;
try
{ 生成数组... }
{ 大小为 0..m-1 , m 等于行数. }
nColumns := Max(0, ADataset.FieldCount-1);
{ 每一元素是大小 (0..n) 的数组,n 等于记录数 }
{ 第0个元素存贮显示字段名. }
nRecords := Max(0, ADataset.RecordCount);
varResultSet := VarArrayCreate([0, nColumns, 0, nRecords],
varVariant);
for m := 0 to nColumns do
varResultSet[m, 0] := ADataset.Fields[m].DisplayLabel;
ADataset.First;
nCurRec := 1; { nCurRec记录当前记录号. }
while not ADataset.Eof do begin
{ 赋字段值. }
for m := 0 to nColumns do
varResultSet[m, nCurRec] := ADataset.Fields[m].Value;
ADataset.Next;
Inc(nCurRec);
end;
except
on E: Exception do
raise Exception.Create('CreateVarArrayFromDataset() - ' +
IntToStr(nRecords) +
' rec,'+IntToStr(nColumns)
+'cols,'+E.Message);
end;
end;