随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253


测试图:



测试代码:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    ClientDataSet2: TClientDataSet;
    DataSource2: TDataSource;
    DBGrid2: TDBGrid;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    CheckListBox1: TCheckListBox;
    procedure Button4Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure CheckListBox1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

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

  DBGrid2.DataSource := DataSource2;
  DataSource2.DataSet := ClientDataSet2;

  with ClientDataSet1 do begin
    FieldDefs.Add('Text', ftString, 12);
    FieldDefs.Add('Num', ftInteger);
    CreateDataSet;
    AppendRecord(['XXX', 111]);
    AppendRecord(['YYY', 222]);
    AppendRecord(['ZZZ', 333]);
  end;
  ClientDataSet2.CloneCursor(ClientDataSet1, False);

  CheckListBox1.Items.CommaText := 'usUnmodified, usModified, usInserted, usDeleted';
end;

procedure TForm1.CheckListBox1Click(Sender: TObject);
var
  i: Integer;
begin
  ClientDataSet2.StatusFilter := [];
  for i := 0 to CheckListBox1.Count - 1 do
  begin
    if CheckListBox1.Checked[i] then
      ClientDataSet2.StatusFilter := ClientDataSet1.StatusFilter + [TUpdateStatus(i)]
  end;
end;

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

procedure TForm1.Button2Click(Sender: TObject);
begin
  ClientDataSet1.Delete;
end;

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

procedure TForm1.Button3Click(Sender: TObject);
begin
  ClientDataSet1.UndoLastChange(True);
end;

end.


测试窗体:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 231
  ClientWidth = 496
  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 ClientDataSet1: TClientDataSet
    Aggregates = <>
    Params = <>
    Left = 64
    Top = 64
  end
  object DataSource1: TDataSource
    DataSet = ClientDataSet1
    Left = 64
    Top = 120
  end
  object DBGrid1: TDBGrid
    Left = 0
    Top = 0
    Width = 193
    Height = 231
    Align = alLeft
    DataSource = DataSource1
    TabOrder = 0
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'Tahoma'
    TitleFont.Style = []
  end
  object ClientDataSet2: TClientDataSet
    Aggregates = <>
    Params = <>
    Left = 344
    Top = 80
  end
  object DataSource2: TDataSource
    Left = 344
    Top = 136
  end
  object DBGrid2: TDBGrid
    Left = 302
    Top = 0
    Width = 194
    Height = 231
    Align = alRight
    TabOrder = 5
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'Tahoma'
    TitleFont.Style = []
  end
  object Button1: TButton
    Left = 199
    Top = 8
    Width = 97
    Height = 25
    Caption = 'Append'
    TabOrder = 4
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 199
    Top = 39
    Width = 97
    Height = 25
    Caption = 'Delete'
    TabOrder = 2
    OnClick = Button2Click
  end
  object Button3: TButton
    Left = 199
    Top = 78
    Width = 97
    Height = 25
    Caption = 'UndoLastChange'
    TabOrder = 3
    OnClick = Button3Click
  end
  object Button4: TButton
    Left = 199
    Top = 109
    Width = 97
    Height = 25
    Caption = 'MergeChangeLog'
    TabOrder = 1
    OnClick = Button4Click
  end
  object CheckListBox1: TCheckListBox
    Left = 199
    Top = 152
    Width = 97
    Height = 70
    ItemHeight = 13
    TabOrder = 6
    OnClick = CheckListBox1Click
  end
end

posted on 2010-02-03 23:00  万一  阅读(...)  评论(...编辑  收藏