unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBTables, DBClient, Grids, DBGrids;
type
TForm1 = class(TForm)
btn1: TButton;
DataSource1: TDataSource;
dbgrd1: TDBGrid;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function 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;
Result:=nil;
raise;
end;
end;
end;
procedure TForm1.btn1Click(Sender: TObject);
var
ADataSet:TDataSet;
begin
ADataSet:=TDataSet.Create(Self);
with ADataSet.FieldDefs do
begin
Add('Name',ftString,30,False);
Add('Value',ftInteger,0,False);
end;
with DataSource1 do
begin
DataSet:=CreateTableInMemory(ADataSet.FieldDefs);
DataSet.Open;
DataSet.Append;
DataSet.FieldByName('Name').AsString:='Woody';
DataSet.FieldByName('Value').AsInteger:=9527;
DataSet.Post;
end;
ADataSet.Free;
end;
end.
