UpdateForm.pas
资源名称:delphi.rar [点击查看]
上传用户:fh681027
上传日期:2022-07-23
资源大小:1959k
文件大小:3k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit UpdateForm;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- IBDatabase, Db, IBCustomDataSet, IBUpdateSQL, IBQuery, DBTables,
- ExtCtrls, DBCtrls, Grids, DBGrids, DBActns, ActnList, ComCtrls, ToolWin;
- type
- TForm1 = class(TForm)
- EmpDS: TDataSource;
- IBQuery1: TIBQuery;
- IBUpdateSQL1: TIBUpdateSQL;
- IBDatabase1: TIBDatabase;
- IBTransaction1: TIBTransaction;
- DBGrid1: TDBGrid;
- IBDataSet1: TIBDataSet;
- ActionList1: TActionList;
- DataSetCancel1: TDataSetCancel;
- DataSetDelete1: TDataSetDelete;
- DataSetEdit1: TDataSetEdit;
- DataSetFirst1: TDataSetFirst;
- DataSetInsert1: TDataSetInsert;
- DataSetLast1: TDataSetLast;
- DataSetNext1: TDataSetNext;
- DataSetPost1: TDataSetPost;
- DataSetPrior1: TDataSetPrior;
- DataSetRefresh1: TDataSetRefresh;
- acCommit: TAction;
- acRollback: TAction;
- ToolBar1: TToolBar;
- ToolButton1: TToolButton;
- ToolButton2: TToolButton;
- ToolButton3: TToolButton;
- ToolButton4: TToolButton;
- ToolButton5: TToolButton;
- ToolButton6: TToolButton;
- ToolButton7: TToolButton;
- ToolButton8: TToolButton;
- ToolButton10: TToolButton;
- ToolButton11: TToolButton;
- ToolButton12: TToolButton;
- ToolButton9: TToolButton;
- procedure FormCreate(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure ActionUpdateTransactions(Sender: TObject);
- procedure acCommitExecute(Sender: TObject);
- procedure acRollbackExecute(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.DFM}
- uses
- Registry;
- procedure TForm1.FormCreate(Sender: TObject);
- var
- Reg: TRegistry;
- begin
- Reg := TRegistry.Create;
- try
- Reg.RootKey := HKEY_LOCAL_MACHINE;
- // Borland Shared/Data
- {Reg.OpenKey('SoftwareBorlandBorland SharedData', False);
- IBDatabase1.DatabaseName := Reg.ReadString('Rootdir') + 'employee.gdb';}
- // InterBase 6 Bin + Sample database path
- Reg.OpenKey('SoftwareBorlandInterBaseCurrentVersion', False);
- IBDatabase1.DatabaseName := Reg.ReadString('RootDirectory') +
- 'examplesdatabaseemployee.gdb';
- finally
- Reg.CloseKey;
- Reg.Free;
- end;
- EmpDS.DataSet.Open;
- end;
- procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
- var
- nCode: Word;
- begin
- if IBTransaction1.InTransaction then
- begin
- nCode := MessageDlg ('Commit Transaction? (No to rollback)',
- mtConfirmation, mbYesNoCancel, 0);
- case nCode of
- mrYes: IBTransaction1.Commit;
- mrNo: IBTransaction1.Rollback;
- mrCancel: Action := caNone; // don't close
- end;
- end;
- end;
- procedure TForm1.ActionUpdateTransactions(Sender: TObject);
- begin
- acCommit.Enabled := IBTransaction1.InTransaction;
- acRollback.Enabled := acCommit.Enabled;
- end;
- procedure TForm1.acCommitExecute(Sender: TObject);
- begin
- IBTransaction1.CommitRetaining;
- end;
- procedure TForm1.acRollbackExecute(Sender: TObject);
- begin
- // or: IBTransaction1.RollbackRetaining;
- IBTransaction1.Rollback;
- IBTransaction1.StartTransaction;
- EmpDS.DataSet.Open;
- end;
- end.