BatchUpdatesU1.pas
上传用户:fh681027
上传日期:2022-07-23
资源大小:1959k
文件大小:2k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit BatchUpdatesU1;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, Grids, DBGrids, ExtCtrls, DB, ADODB, StdCtrls;
  6. type
  7.   TForm1 = class(TForm)
  8.     ADODataSet1: TADODataSet;
  9.     DataSource1: TDataSource;
  10.     Panel1: TPanel;
  11.     DBGrid1: TDBGrid;
  12.     Button1: TButton;
  13.     CheckBox1: TCheckBox;
  14.     ADOConnection1: TADOConnection;
  15.     Button2: TButton;
  16.     Button3: TButton;
  17.     procedure Button1Click(Sender: TObject);
  18.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  19.     procedure CheckBox1Click(Sender: TObject);
  20.     procedure Button2Click(Sender: TObject);
  21.     procedure Button3Click(Sender: TObject);
  22.   private
  23.     { Private declarations }
  24.   public
  25.     { Public declarations }
  26.   end;
  27. var
  28.   Form1: TForm1;
  29. implementation
  30. {$R *.dfm}
  31. procedure TForm1.Button1Click(Sender: TObject);
  32. begin
  33.   ADODataSet1.UpdateBatch;
  34. end;
  35. function ADOUpdatesPending(ADODataSet: TCustomADODataSet): boolean;
  36. var
  37.   Clone: TADODataSet;
  38. begin
  39.   Clone:=TADODataSet.Create(nil);
  40.   try
  41.     Clone.Clone(ADODataSet);
  42.     Clone.FilterGroup:=fgPendingRecords;
  43.     Clone.Filtered   :=True;
  44.     Result:=not (Clone.BOF and Clone.EOF);
  45.   finally
  46.     Clone.Free;
  47.   end;
  48. end;
  49. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  50. begin
  51.   CanClose:=True;
  52.   if ADOUpdatesPending(ADODataSet1) then
  53.     CanClose:=(MessageDlg('Updates are still pending'+#13#10+
  54.     'Close anyway ?', mtConfirmation, [mbYes, mbNo], 0)=mrYes);
  55. end;
  56. procedure TForm1.CheckBox1Click(Sender: TObject);
  57. begin
  58.   if CheckBox1.Checked then
  59.   begin
  60.     ADOConnection1.Connected:=True;
  61.     ADODataSet1.Connection:=ADOConnection1;
  62.   end
  63.   else
  64.   begin
  65.     ADODataSet1.Connection:=nil;
  66.     ADOConnection1.Connected:=False;
  67.   end;
  68. end;
  69. procedure TForm1.Button2Click(Sender: TObject);
  70. begin
  71.   ADODataSet1.SaveToFile('Local.ADTG');
  72. end;
  73. procedure TForm1.Button3Click(Sender: TObject);
  74. begin
  75.   ADODataSet1.SaveToFile('Local.XML', pfXML);
  76. end;
  77. end.