新建一 DataSet , 並加入數據 : prepareTable
function TFrm_Print.CreateTableInMemory(const AFieldDefs:TFIEldDefs):TDataSet;
var
TempTable:TClIEntDataSet;
begin
TempTable:=nil;
Result:=nil;
if AFIEldDefs<>nil then
begin
try
TempTable:=TClIEntDataSet.Create(Application);
TempTable.FieldDefs.Assign(AFIEldDefs);
TempTable.CreateDataSet;
Result:=(TempTable as TDataSet);
Except
if TempTable<>nil then
TempTable.Free;
raise;
end
end;
end;
procedure TFrm_Print.CreateDataSet(var gDataSet:Tdataset);
var ADataSet:TDataSet;
begin
try
if assigned(gDataSet) then gDataSet.free;
except
end;
ADataSet:=TDataSet.Create(Self);
try
with ADataSet.FIEldDefs do
begin
add('OrderNo',ftInteger);
add('prjName',ftString,200);
add('srcPrice',ftFloat);
end;
gDataSet:=CreateTableInMemory(ADataSet.FIEldDefs);
gDataSet.Open;
finally
ADataSet.Free;
end;
end;
procedure Tfrm_GoodsMg.prepareTable(var gDataSet:Tdataset);
procedure prepareDataSet;
begin
{ while not 數據源.eof do begin
gDataSet.append;
gDataSet.fIEldbyname('OrderNo').asInteger:= I_Value;
gDataSet.fIEldbyname('prjName').asString := A_Value;
gDataSet.fIEldbyname('OrderNo').asFloat := D_value;
gDataSet.post;
數據源.next;
end; }
end;
begin
CreateDataSet(gDataSet);
prepareDataSet;
end;
procedure getMyDataSet()
var myDataSet:Tdataset
begin
prepareTable(myDataSet);
myDataSet.free;
end;