home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / Runimage / Delphi50 / Demos / Db / Cachedup / datamod.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-11  |  1.6 KB  |  61 lines

  1. unit DataMod;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   DB, DBTables;
  8.  
  9. type
  10.   TCacheData = class(TDataModule)
  11.     CacheDS: TDataSource;
  12.     CacheDB: TDatabase;
  13.     CacheQuery: TQuery;
  14.     UpdateSQL: TUpdateSQL;
  15.     CacheQueryUpdateStatus: TStringField;
  16.     CacheQueryPROJ_ID: TStringField;
  17.     CacheQueryPROJ_NAME: TStringField;
  18.     procedure UpdateErrorHandler(DataSet: TDataSet; E: EDatabaseError;
  19.       UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
  20.     procedure CacheQueryCalcFields(DataSet: TDataSet);
  21.   private
  22.     { Private declarations }
  23.   public
  24.     { Public declarations }
  25.   end;
  26.  
  27. var
  28.   CacheData: TCacheData;
  29.  
  30. implementation
  31.  
  32. uses CachedUp, ErrForm;
  33.  
  34. {$R *.DFM}
  35.  
  36. { This event is triggered when an error occurs during the update process
  37.   (such as a key violation).  Here we use another form to show the user
  38.   the error and allow them to decide what to do about it.  See ErrForm.pas
  39.   for more information }
  40.  
  41. procedure TCacheData.UpdateErrorHandler(DataSet: TDataSet;
  42.   E: EDatabaseError; UpdateKind: TUpdateKind;
  43.   var UpdateAction: TUpdateAction);
  44. begin
  45.   UpdateAction := UpdateErrorForm.HandleError(DataSet, E, UpdateKind);
  46. end;
  47.  
  48. { This event displays the current update status in a calculated field }
  49.  
  50. procedure TCacheData.CacheQueryCalcFields(DataSet: TDataSet);
  51. const
  52.   UpdateStatusStr: array[TUpdateStatus] of string = ('Unmodified', 'Modified',
  53.    'Inserted', 'Deleted');
  54. begin
  55.   if CacheQuery.CachedUpdates then
  56.     CacheQueryUpdateStatus.Value := UpdateStatusStr[CacheQuery.UpdateStatus];
  57. end;
  58.  
  59. end.
  60.  
  61.