首页  编辑  

判断ADO数据集是否还有数据没有提交

Tags: /超级猛料/Friends.网友专栏/zswang/函数大全/   Date Created:
(* //
  标题:判断ADO数据集是否还有数据没有提交
  说明:等待升级
  设计:3fly
  整理:Zswang
  日期:2002-03-03
  支持:wjhu111@21cn.com
  // *)
/// ////Begin Source
function CacheNotSave(mDataSet: TCustomADODataSet): Boolean;
{ 返回ADO数据集是否还有数据没有提交 }
var
    vFiltered: Boolean;
    vFilterGroup: TFilterGroup;
    vBookmark: string;
begin
    Result := False;
    if not mDataSet.Active then
        Exit;
    if mDataSet.LockType <> ltBatchOptimistic then
        Exit;
    vBookmark := mDataSet.Bookmark;
    mDataSet.DisableControls;
    try
        vFiltered := mDataSet.Filtered;
        vFilterGroup := mDataSet.FilterGroup;
        try
            mDataSet.Filtered := True;
            mDataSet.FilterGroup := fgPendingRecords;
            Result := mDataSet.RecordCount > 0;
        finally
            mDataSet.Filtered := vFiltered;
            mDataSet.FilterGroup := vFilterGroup;
        end;
    finally
        mDataSet.Bookmark := vBookmark;
        mDataSet.EnableControls;
    end;
end; { CacheNotSave }

/// ////End Source
/// ////Begin Demo
procedure TForm1.Button1Click(Sender: TObject);
begin
    ADOTable1.UpdateBatch;
    CheckBox1.Checked := CacheNotSave(ADOTable1);
    // ActionUpdateBatch.Enabled := CacheNotSave(ADOTable1);
end;

procedure TForm1.ADOTable1AfterCancel(DataSet: TDataSet);
begin
    CheckBox1.Checked := CacheNotSave(TCustomADODataSet(DataSet));
end;

procedure TForm1.ADOTable1AfterPost(DataSet: TDataSet);
begin
    CheckBox1.Checked := CacheNotSave(TCustomADODataSet(DataSet));
end;

procedure TForm1.ADOTable1AfterDelete(DataSet: TDataSet);
begin
    CheckBox1.Checked := CacheNotSave(TCustomADODataSet(DataSet));
end;

procedure TForm1.ADOTable1AfterOpen(DataSet: TDataSet);
begin
    CheckBox1.Checked := CacheNotSave(TCustomADODataSet(DataSet));
end;
/// ////End Demo