那就这里了,各位没看懂可不能怪我呀 :)
其实关键的还是在dfm里
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids, DBGrids, DB, ADODB, Provider, DBClient;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ClientDataSet1: TClientDataSet;
DataSetProvider1: TDataSetProvider;
BitBtn3: TBitBtn;
Memo1: TMemo;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn4: TBitBtn;
BitBtn5: TBitBtn;
Label1: TLabel;
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//显示
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
memo1.lines.clear;
with clientdataset1 do
begin
////////////////////
StatusFilter := [usModified, usInserted, usDeleted];
Filtered := True;
while not eof do
begin
case UpdateStatus of
usModified : Memo1.Lines.Add('修改: '+vartostr(fields[1].oldvalue)+' => '+fields[1].asstring);
usInserted : Memo1.Lines.Add('新增: '+fields[1].asstring);
usDeleted : Memo1.Lines.Add('删除: '+vartostr(fields[1].oldvalue));
end;
next;
end;
StatusFilter := [];
end;
end;
//将修改过的记录过滤出来
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
clientdataset1.StatusFilter := [usModified, usInserted, usDeleted];
clientdataset1.Filtered := True;
end;
//取消过滤
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
clientdataset1.StatusFilter := [];
end;
//取消修改
procedure TForm1.BitBtn4Click(Sender: TObject);
begin
clientdataset1.cancelupdates
end;
//提交修改
procedure TForm1.BitBtn5Click(Sender: TObject);
begin
clientdataset1.applyupdates(-1);
end;
dfm内容:
object Form1: TForm1
Left = 192
Top = 133
Width = 622
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 8
Top = 352
Width = 342
Height = 13
Caption = '设置过滤后就是过滤出已经修改的记录(包括新增,修改,删除)。'
end
object DBGrid1: TDBGrid
Left = 8
Top = 8
Width = 337
Height = 297
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object BitBtn3: TBitBtn
Left = 352
Top = 312
Width = 75
Height = 25
Caption = '显示状态'
TabOrder = 1
OnClick = BitBtn3Click
end
object Memo1: TMemo
Left = 352
Top = 8
Width = 249
Height = 297
TabOrder = 2
end
object BitBtn1: TBitBtn
Left = 8
Top = 312
Width = 75
Height = 25
Caption = '过滤'
TabOrder = 3
OnClick = BitBtn1Click
end
object BitBtn2: TBitBtn
Left = 96
Top = 312
Width = 75
Height = 25
Caption = '取消过滤'
TabOrder = 4
OnClick = BitBtn2Click
end
object BitBtn4: TBitBtn
Left = 176
Top = 312
Width = 75
Height = 25
Caption = '取消修改'
TabOrder = 5
OnClick = BitBtn4Click
end
object BitBtn5: TBitBtn
Left = 256
Top = 312
Width = 75
Height = 25
Caption = '提交修改'
TabOrder = 6
OnClick = BitBtn5Click
end
object ADOConnection1: TADOConnection
Connected = True
ConnectionString =
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Documents and Se' +
'ttings/zj.ZHOUJUN/桌面/TEST/记录状态/db1.mdb;Persist Security Info=Fal' +
'se'
LoginPrompt = False
Mode = cmShareDenyNone
Provider = 'Microsoft.Jet.OLEDB.4.0'
Left = 104
Top = 112
end
object ADOTable1: TADOTable
Connection = ADOConnection1
CursorType = ctStatic
TableName = '表1'
Left = 120
Top = 192
end
//////////////////////////////////////就这下面的关键了
object DataSource1: TDataSource
DataSet = ClientDataSet1
Left = 216
Top = 120
end
object ClientDataSet1: TClientDataSet
Active = True
Aggregates = <>
Params = <>
ProviderName = 'DataSetProvider1'
Left = 128
Top = 160
end
object DataSetProvider1: TDataSetProvider
DataSet = ADOTable1
Left = 232
Top = 264
end
end