home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 53 / IOPROG_53.ISO / soft / c++ / xceedbkp.exe / Samples / Delphi4 / RollbackForm.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-09-02  |  4.5 KB  |  126 lines

  1. unit RollbackForm;
  2. {------------------------------------------------------------------------------}
  3. { RollbackForm.pas: List of file dates available in backup files.              }
  4. {                                                                              }
  5. { Part of the Delphi 4 Sample application for the Xceed Backup Library         }
  6. { Copyright (C) 1999 - Xceed Software Inc.                                     }
  7. {------------------------------------------------------------------------------}
  8.  
  9. interface
  10.  
  11. uses
  12.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  13.   StdCtrls, OleCtrls, XceedBackupLib_TLB;
  14.  
  15. type
  16.   TfrmRollback = class(TForm)
  17.     Label1: TLabel;
  18.     lstFiles: TListBox;
  19.     chkLatest: TCheckBox;
  20.     btRestore: TButton;
  21.     btCancel: TButton;
  22.     procedure chkLatestClick(Sender: TObject);
  23.     procedure btRestoreClick(Sender: TObject);
  24.     procedure btCancelClick(Sender: TObject);
  25.     procedure BrowsingCatalogEntry(Sender: TObject;
  26.       const sFilename: WideString; lSize: Integer; xAttributes: TOleEnum;
  27.       dtLastModified, dtLastAccessed, dtCreated: TDateTime;
  28.       lDiskNumber: Integer; const sMediaLabel: WideString);
  29.     procedure lstFilesClick(Sender: TObject);
  30.     procedure lstFilesDblClick(Sender: TObject);
  31.   private
  32.     { Private declarations }
  33.     procedure UpdateRestoreState;
  34.   public
  35.     { Public declarations }
  36.     { We voluntarily hide the default ShowModal method }
  37.     function ShowModal( xMain : TXceedBackup; xFiles : TFileSelection ) : integer;
  38.   end;
  39.  
  40. var
  41.   frmRollback: TfrmRollback;
  42.  
  43. implementation
  44.  
  45. {$R *.DFM}
  46.  
  47. {------------------------------------------------------------------------------}
  48. { ShowModal: Our version of this virtual method. We fill the list of available }
  49. { file dates before showing the form modally.                                  }
  50. {------------------------------------------------------------------------------}
  51. function TfrmRollback.ShowModal( xMain : TXceedBackup; xFiles : TFileSelection ) : integer;
  52. begin
  53.   lstFiles.Items.Clear;
  54.  
  55.   { For our Rollback form, we wrote a handler for the XceedBackup control's
  56.     OnBrowsingCatalogEntry event that adds browsed entries to our listbox.
  57.     We assign the handler now (instead of using the object inspector) so that
  58.     the main Sample form is not notified about catalog entries being listed. }
  59.   xMain.OnBrowsingCatalogEntry  := BrowsingCatalogEntry;
  60.  
  61.   { Browse the catalogs. The 'xFiles' TFileSelection control contains the
  62.     filename of the text file we are interested in. }
  63.   xMain.BrowseCatalogs( xFiles.ControlInterface, 'Delphi Sample' );
  64.  
  65.   { Unnasign our BrowsingCatalogEntry handler }
  66.   xMain.OnBrowsingCatalogEntry  := nil;
  67.  
  68.   UpdateRestoreState;
  69.   Result := inherited ShowModal;
  70.  
  71.   if Result = 1 then
  72.   begin
  73.     if chkLatest.Checked then { To restore latest file, set date to 9999/12/31 }
  74.       xFiles.MaxDate := EncodeDate( 9999, 12, 31 )
  75.     else { Otherwise, set the date to the listbox's selected date  }
  76.       xFiles.MaxDate := StrToDateTime( lstFiles.Items.Strings[ lstFiles.ItemIndex ] );
  77.   end;
  78. end;
  79.  
  80. {------------------------------------------------------------------------------}
  81. { BrowsingCatalogEntry event: This is the event we manually assigned above.    }
  82. { It is triggered for each entry found in a catalog. We add the entry to       }
  83. { the listbox                                                                  }
  84. {------------------------------------------------------------------------------}
  85. procedure TfrmRollback.BrowsingCatalogEntry(Sender: TObject;
  86.   const sFilename: WideString; lSize: Integer; xAttributes: TOleEnum;
  87.   dtLastModified, dtLastAccessed, dtCreated: TDateTime;
  88.   lDiskNumber: Integer; const sMediaLabel: WideString);
  89. begin
  90.   lstFiles.Items.Add( DateTimeToStr( dtLastModified ) );
  91. end;
  92.  
  93. procedure TfrmRollback.UpdateRestoreState;
  94. begin
  95.   btRestore.Enabled := chkLatest.Checked or ( lstFiles.ItemIndex >= 0 );
  96. end;
  97.  
  98. procedure TfrmRollback.chkLatestClick(Sender: TObject);
  99. begin
  100.   UpdateRestoreState;
  101. end;
  102.  
  103. procedure TfrmRollback.btRestoreClick(Sender: TObject);
  104. begin
  105.   ModalResult := mrOK;
  106. end;
  107.  
  108. procedure TfrmRollback.btCancelClick(Sender: TObject);
  109. begin
  110.   ModalResult := mrCancel;
  111. end;
  112.  
  113. procedure TfrmRollback.lstFilesClick(Sender: TObject);
  114. begin
  115.   UpdateRestoreState;
  116. end;
  117.  
  118. procedure TfrmRollback.lstFilesDblClick(Sender: TObject);
  119. begin
  120.   UpdateRestoreState;
  121.   if btRestore.Enabled then
  122.     ModalResult := mrOK;
  123. end;
  124.  
  125. end.
  126.