unit Form_Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, DBClient;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
ClientDataSet1: TClientDataSet;
procedure FormCreate(Sender: TObject);
private
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
with ClientDataSet1 do
begin
FieldDefs.Add('ID', ftInteger, 0, False);
FieldDefs.Add('Name', ftString, 10, False);
FieldDefs.Add('Gender', ftInteger, 0, False);
FieldDefs.Add('Age', ftInteger, 0, False);
IndexDefs.Add('PK', 'ID', [ixPrimary, ixUnique]);
CreateDataSet;
DisableControls;
for i := 1 to 1000 do
begin
Append;
FieldByName('ID').AsInteger := i;
FieldByName('Name').AsString := 'User' + IntToStr(i);
FieldByName('Gender').AsInteger := Random(2);
FieldByName('Age').AsInteger := Random(100);
Post;
end;
EnableControls;
end;
end;
end.
procedure TFormMain.FormCreate(Sender: TObject);
begin
self.ClientDataSet1.FieldDefs.Add('Name',ftString,50);
self.ClientDataSet1.FieldDefs.Add('Age',ftString,50);
self.ClientDataSet1.CreateDataSet;
self.ClientDataSet1.AppendRecord(['100','100']);
self.ClientDataSet1.AppendRecord(['100','100']);
self.ClientDataSet1.AppendRecord(['100','100']);
self.ClientDataSet1.AppendRecord(['100','100']);
self.ClientDataSet1.AppendRecord(['100','100']);
self.ClientDataSet1.AppendRecord(['100','100']);
self.DataSource1.DataSet:=self.ClientDataSet1;
end;
procedure TFormMain.BitBtn1Click(Sender: TObject);
begin
self.ClientDataSet1.AppendRecord(['1001','100']);//添加新纪录
self.ClientDataSet2.Data:=self.ClientDataSet1.Delta;
self.DataSource1.DataSet:=self.ClientDataSet2;
end;