自定义DataSet,并写入数据
2006-02-04 13:50:18 来源:WEB开发网新建一 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;
更多精彩
赞助商链接