unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, Grids, DBGrids, StdCtrls, ADODB;
type
TForm1 = class(TForm)
ClientDataSet1: TClientDataSet;
ClientDataSet1ID: TIntegerField;
ClientDataSet1Name: TStringField;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i:Integer;
begin
ClientDataSet1.Active :=False;
ClientDataSet1.CreateDataSet;
ClientDataSet1.IndexDefs.AddIndexDef.Fields :='ID';
ClientDataSet1.IndexDefs.AddIndexDef.Name:='Idx_ID';
ClientDataSet1.EmptyDataSet;
ClientDataSet1.Active :=True;
for i:=0 to 9 do
begin
ClientDataSet1.Append ;
ClientDataSet1.fieldbyname('ID').Value :=i+1;
ClientDataSet1.fieldbyname('Name').Value :=FormatFloat('000',i+1);
ClientDataSet1.Post;
end;
end;
end.
--------------------------------
object Form1: TForm1
Left = 619
Top = 377
Width = 338
Height = 393
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 0
Top = 0
Width = 233
Height = 355
Align = alLeft
DataSource = DataSource1
ImeName = '中文(简体) - 搜狗拼音输入法'
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object Button1: TButton
Left = 240
Top = 160
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
object ClientDataSet1: TClientDataSet
Aggregates = <>
Params = <>
Left = 192
Top = 16
object ClientDataSet1ID: TIntegerField
FieldName = 'ID'
end
object ClientDataSet1Name: TStringField
FieldName = 'Name'
end
end
object DataSource1: TDataSource
DataSet = ClientDataSet1
Left = 112
Top = 56
end
end