我也来贴一下,DataSetToOleVariant,来自康伟的主页,上面也有跟eyes的例子相似
的函数。就是把数据拷到二维的Variant数组中,在客户端把这个OleVariant解开就行。
procedure CreateVarArrayFromDataset(var varResultSet: OleVariant;
ADataset : TDataset);
var
m : Integer;
nRecords, nColumns, nCurRec : Integer;
begin
nRecords := -1;
nColumns := -1;
try
{ Create the array... }
{ Set size to 0..m-1 where m equals the number of columns. }
nColumns := Max(0, ADataset.FieldCount-1);
{Each item is an array of size (0..n) where n equals the number of records.
Entry 0 is where we store the column name. }
nRecords := Max(0, ADataset.RecordCount);
varResultSet := VarArrayCreate([0, nColumns, 0, nRecords], varVariant);
for m := 0 to nColumnsdo
varResultSet[m, 0] := ADataset.Fields[m].DisplayLabel;
{ Populate from result set. }
ADataset.First;
nCurRec := 1;
{ Current record number. }
while not ADataset.Eofdo
begin
{ Put in field values. }
for m := 0 to nColumnsdo
varResultSet[m, nCurRec] := ADataset.Fields[m].Value;
ADataset.Next;
Inc(nCurRec);
end;
except
on E: Exceptiondo
raise Exception.Create('CreateVarArrayFromDataset() - ' +
IntToStr(nRecords) +
' rec,'+IntToStr(nColumns)+'cols,'+E.Message);
end;
end;