相關成員不少, 不親自測試很難徹底了解其細節; 下面是我的測試:
查看原圖(大圖)
測試代碼:
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