TClientDataSet[15]: 测试添加与恢复


相关成员不少, 不亲自测试很难彻底了解其细节; 下面是我的测试:

TClientDataSet[15]: 测试添加与恢复_第1张图片

测试代码:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, DBClient, Grids, DBGrids;

type
  TForm1 = class(TForm)
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button12: TButton;
    Button11: TButton;
    Button13: TButton;
    Button14: TButton;
    Button15: TButton;
    Button16: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button19Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure Button16Click(Sender: TObject);
  private
    procedure ViewXML;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses xmldoc;

procedure TForm1.ViewXML;
begin
  if not(ClientDataSet1.State in [dsEdit, dsInsert]) then
  begin
    Text := Format('ChangeCount: %d', [ClientDataSet1.ChangeCount]);
    Memo1.Text := FormatXMLData(ClientDataSet1.XMLData);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DBGrid1.DataSource := DataSource1;
  DataSource1.DataSet := ClientDataSet1;

  with ClientDataSet1 do begin
    FieldDefs.Add('Text', ftString, 12);
    FieldDefs.Add('Num', ftInteger);
    CreateDataSet;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ClientDataSet1.AppendRecord(['AAA', 999]);
  ViewXML;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ClientDataSet1.InsertRecord(['III', 111]);
  ViewXML;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  if not ClientDataSet1.IsEmpty then
    ClientDataSet1.Delete;
  ViewXML;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  ClientDataSet1.Append;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  ClientDataSet1.Insert;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  ClientDataSet1.Edit;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
  if ClientDataSet1.State in [dsEdit, dsInsert] then
    ClientDataSet1.Post;
  ViewXML;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
  if ClientDataSet1.Modified then
    ClientDataSet1.Cancel;
  ViewXML;
end;

procedure TForm1.Button19Click(Sender: TObject);
begin
  if ClientDataSet1.State in [dsEdit, dsInsert] then
    ClientDataSet1.SetFields(['XXX', 0]);
  ViewXML;
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
  if ClientDataSet1.State in [dsEdit, dsInsert] then
    ClientDataSet1.ClearFields;
  ViewXML;
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
  ClientDataSet1.RevertRecord;
  ViewXML;
end;

procedure TForm1.Button12Click(Sender: TObject);
begin
  if ClientDataSet1.ChangeCount > 0 then
    ClientDataSet1.UndoLastChange(True);
  ViewXML;
end;

procedure TForm1.Button13Click(Sender: TObject);
begin
  ClientDataSet1.CancelUpdates;
  ViewXML;
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
  ClientDataSet1.MergeChangeLog;
  ClientDataSet1.Tag := 0;
  ViewXML;
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
  ClientDataSet1.Tag := ClientDataSet1.SavePoint;
  ViewXML;
end;

procedure TForm1.Button16Click(Sender: TObject);
begin
  if ClientDataSet1.Tag > 0 then
    ClientDataSet1.SavePoint := ClientDataSet1.Tag;
  ViewXML;
end;

end.

 
 

测试窗体:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 418
  ClientWidth = 666
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object DBGrid1: TDBGrid
    Left = 0
    Top = 0
    Width = 185
    Height = 418
    Align = alLeft
    TabOrder = 0
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'Tahoma'
    TitleFont.Style = []
  end
  object Memo1: TMemo
    Left = 331
    Top = 0
    Width = 335
    Height = 418
    Align = alRight
    Anchors = [akLeft, akTop, akRight, akBottom]
    Lines.Strings = (
      'Memo1')
    ScrollBars = ssVertical
    TabOrder = 17
    ExplicitWidth = 313
  end
  object Button1: TButton
    Left = 191
    Top = 8
    Width = 132
    Height = 25
    Caption = 'AppendRecord'
    TabOrder = 1
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 191
    Top = 39
    Width = 132
    Height = 25
    Caption = 'InsertRecord'
    TabOrder = 2
    OnClick = Button2Click
  end
  object Button3: TButton
    Left = 191
    Top = 70
    Width = 132
    Height = 25
    Caption = 'Delete'
    TabOrder = 3
    OnClick = Button3Click
  end
  object Button4: TButton
    Left = 191
    Top = 112
    Width = 50
    Height = 25
    Caption = 'Append'
    TabOrder = 4
    OnClick = Button4Click
  end
  object Button5: TButton
    Left = 244
    Top = 112
    Width = 42
    Height = 25
    Caption = 'Insert'
    TabOrder = 5
    OnClick = Button5Click
  end
  object Button6: TButton
    Left = 289
    Top = 112
    Width = 34
    Height = 25
    Caption = 'Edit'
    TabOrder = 6
    OnClick = Button6Click
  end
  object Button7: TButton
    Left = 191
    Top = 143
    Width = 65
    Height = 25
    Caption = 'Post'
    TabOrder = 7
    OnClick = Button7Click
  end
  object Button8: TButton
    Left = 263
    Top = 143
    Width = 62
    Height = 25
    Caption = 'Cancel'
    TabOrder = 8
    OnClick = Button8Click
  end
  object Button9: TButton
    Left = 192
    Top = 174
    Width = 63
    Height = 25
    Caption = 'SetFields'
    TabOrder = 9
  end
  object Button10: TButton
    Left = 261
    Top = 174
    Width = 62
    Height = 25
    Caption = 'ClearFields'
    TabOrder = 10
    OnClick = Button10Click
  end
  object Button12: TButton
    Left = 191
    Top = 248
    Width = 132
    Height = 25
    Caption = 'UndoLastChange'
    TabOrder = 11
    OnClick = Button12Click
  end
  object Button11: TButton
    Left = 191
    Top = 205
    Width = 132
    Height = 25
    Caption = 'RevertRecord'
    TabOrder = 12
    OnClick = Button11Click
  end
  object Button13: TButton
    Left = 191
    Top = 279
    Width = 132
    Height = 25
    Caption = 'CancelUpdates'
    TabOrder = 13
    OnClick = Button13Click
  end
  object Button14: TButton
    Left = 191
    Top = 310
    Width = 132
    Height = 25
    Caption = 'MergeChangeLog'
    TabOrder = 14
    OnClick = Button14Click
  end
  object Button15: TButton
    Left = 191
    Top = 352
    Width = 132
    Height = 25
    Caption = 'SavePoint(Get)'
    TabOrder = 15
    OnClick = Button15Click
  end
  object Button16: TButton
    Left = 191
    Top = 383
    Width = 132
    Height = 25
    Caption = 'SavePoint(Set)'
    TabOrder = 16
    OnClick = Button16Click
  end
  object ClientDataSet1: TClientDataSet
    Aggregates = <>
    Params = <>
    Left = 64
    Top = 104
  end
  object DataSource1: TDataSource
    Left = 64
    Top = 176
  end
end

 
 

你可能感兴趣的:(client)