home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / Runimage / Delphi50 / Demos / Midas / Empedit / empform.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-11  |  3.2 KB  |  111 lines

  1. unit EmpForm;
  2.  
  3. {
  4.   This program demonstrates using TClientDataSet in a distributed data
  5.   application.  The data comes from a separate OLE Automation server,
  6.   so before running this project you must compile and run EmpServ.dpr.
  7. }
  8.  
  9. interface
  10.  
  11. uses
  12.   SysUtils, Forms, Dialogs, ExtCtrls, StdCtrls, Mask, Classes,
  13.     DBClient, Db, Controls, DBCtrls, ComCtrls, MConnect;
  14.  
  15. type
  16.   TEmployeeForm = class(TForm)
  17.     Label2: TLabel;
  18.     UpdateButton: TButton;
  19.     UndoButton: TButton;
  20.     QueryButton: TButton;
  21.     DBText1: TDBText;
  22.     FirstName: TDBEdit;
  23.     LastName: TDBEdit;
  24.     PhoneExt: TDBEdit;
  25.     HireDate: TDBEdit;
  26.     Salary: TDBEdit;
  27.     EmpData: TDataSource;
  28.     DBNavigator1: TDBNavigator;
  29.     Employees: TClientDataSet;
  30.     RemoteServer1: TDCOMConnection;
  31.     StatusBar1: TStatusBar;
  32.     procedure QueryButtonClick(Sender: TObject);
  33.     procedure UpdateButtonClick(Sender: TObject);
  34.     procedure UndoButtonClick(Sender: TObject);
  35.     procedure EmployeesReconcileError(DataSet: TClientDataSet;
  36.      E: EReconcileError; UpdateKind: TUpdateKind; var Action: TReconcileAction);
  37.     procedure EmpDataDataChange(Sender: TObject; Field: TField);
  38.   end;
  39.  
  40. var
  41.   EmployeeForm: TEmployeeForm;
  42.  
  43. implementation
  44.  
  45. uses RecError;
  46.  
  47. {$R *.DFM}
  48.  
  49. procedure TEmployeeForm.QueryButtonClick(Sender: TObject);
  50. begin
  51.  
  52. { Get data from the server.  The number of records returned is dependent on
  53.   the PacketRecords property of TClientDataSet.  If PacketRecords is set
  54.   to -1 then all records are returned.  Otherwise, as the user scrolls
  55.   through the data, additional records are returned in separate data packets. }
  56.  
  57.   Employees.Close;
  58.   Employees.Open;
  59.  
  60. end;
  61.  
  62. procedure TEmployeeForm.UpdateButtonClick(Sender: TObject);
  63. begin
  64.  
  65. { Apply any edits.  The parameter indicates the number of errors which
  66.   are allowed before the updating is aborted.  A value of -1 indicates that
  67.   all successful updates be applied regardless of the number of errors. }
  68.  
  69.   Employees.ApplyUpdates(-1);
  70.   
  71. end;
  72.  
  73. procedure TEmployeeForm.UndoButtonClick(Sender: TObject);
  74. begin
  75.  
  76. { Here we demonstrate a new feature in TClientDataSet, the ability to undo
  77.   changes in reverse order.  The parameter indicates if the cursor should
  78.   be repositioned to then record association with the change. }
  79.  
  80.  
  81.   Employees.UndoLastChange(True);
  82.  
  83. end;
  84.  
  85. procedure TEmployeeForm.EmployeesReconcileError(DataSet: TClientDataSet;
  86.   E: EReconcileError; UpdateKind: TUpdateKind; var Action: TReconcileAction);
  87. begin
  88.  
  89. { This is the event handler which is called when there are errors during the
  90.   update process.  To demonstrate, you can create an error by running two
  91.   copies of this application and modifying the same record in each one.
  92.   Here we use the standard reconcile error dialog from the object repository. }
  93.  
  94.   Action := HandleReconcileError(DataSet, UpdateKind, E);
  95. end;
  96.  
  97. procedure TEmployeeForm.EmpDataDataChange(Sender: TObject; Field: TField);
  98. begin
  99.  
  100. { This code is used to update the status bar to show the number of records
  101.   that have been retrieved an our relative position with the dataset. }
  102.  
  103.   with Employees do
  104.     if Active then
  105.       StatusBar1.Panels[1].Text := Format(' %d of %d', [RecNo, RecordCount]);
  106.  
  107. end;
  108.  
  109.  
  110. end.
  111.