home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d56 / RMCTL.ZIP / rmDataStoragePropEdit.pas < prev    next >
Pascal/Delphi Source File  |  2001-06-22  |  3KB  |  132 lines

  1. {================================================================================
  2. Copyright (C) 1997-2001 Mills Enterprise
  3.  
  4. Unit     : rmDataStoragePropEdit
  5. Purpose  : The property and component editors for the rmDataStorage components
  6. Date     : 12-29-2000
  7. Author   : Ryan J. Mills
  8. Version  : 1.80
  9. ================================================================================}
  10.  
  11. unit rmDataStoragePropEdit;
  12.  
  13. interface
  14.  
  15. {$I CompilerDefines.INC}
  16.  
  17. {$ifdef BD6}
  18. uses
  19.   DesignIntf, DesignEditors, TypInfo;    
  20. {$else}
  21. uses
  22.   DsgnIntf, TypInfo;
  23. {$endif}
  24.  
  25. type
  26.   TrmDataLongintProperty = class(TIntegerProperty)
  27.   public
  28.     function GetAttributes: TPropertyAttributes; override;
  29.   end;
  30.  
  31.   TrmDataStorageEditor = class(TComponentEditor)
  32.   private
  33.     procedure SaveToFile;
  34.     procedure LoadFromFile;
  35.     procedure ClearData;
  36.   public
  37.     function GetVerb(index:integer):string; override;
  38.     function GetVerbCount:integer; override;
  39.     procedure ExecuteVerb(index:integer); override;
  40.   end;
  41.  
  42.  
  43. implementation
  44.  
  45. uses
  46.   rmDataStorage, dialogs;
  47.  
  48. { TrmDataLongintProperty }
  49.  
  50. function TrmDataLongintProperty.GetAttributes: TPropertyAttributes;
  51. begin
  52.    Result := [paReadOnly];
  53. end;
  54.  
  55. { TrmDataStorageEditor }
  56.  
  57. procedure TrmDataStorageEditor.ClearData;
  58. begin
  59.    if assigned(Component) then
  60.    begin
  61.       TrmCustomDataStorage(Component).ClearData;
  62.       designer.modified;
  63.    end;
  64. end;
  65.  
  66. procedure TrmDataStorageEditor.ExecuteVerb(index: integer);
  67. begin
  68.    case index of
  69.         0:LoadFromFile;
  70.         1:SaveToFile;
  71.         2:ClearData;
  72.    end;
  73. end;
  74.  
  75. function TrmDataStorageEditor.GetVerb(index: integer): string;
  76. begin
  77.    case index of
  78.         0:result := 'Load data from file...';
  79.         1:result := 'Save data to file...';
  80.         2:result := 'Clear data';
  81.    end;
  82. end;
  83.  
  84. function TrmDataStorageEditor.GetVerbCount: integer;
  85. begin
  86.    result := 3;
  87. end;
  88.  
  89. procedure TrmDataStorageEditor.LoadFromFile;
  90. begin
  91.    if assigned(Component) then
  92.    begin
  93.       with TOpenDialog.create(nil) do
  94.       try
  95.          Title := 'Load file...';
  96.          Filter := 'All Files|*.*';
  97.          FilterIndex := 1;
  98.          if execute then
  99.          begin
  100.             TrmCustomDataStorage(Component).LoadFromFile(filename);
  101.             designer.modified;
  102.          end;
  103.       finally
  104.          free;
  105.       end
  106.    end;
  107. end;
  108.  
  109. procedure TrmDataStorageEditor.SaveToFile;
  110. begin
  111.    if assigned(Component) then
  112.    begin
  113.       if TrmCustomDataStorage(Component).DataSize = 0 then
  114.       begin
  115.          ShowMessage('Component contains no data.');
  116.          exit;  
  117.       end;
  118.       with TSaveDialog.create(nil) do
  119.       try
  120.          Title := 'Save to...';
  121.          Filter := 'All Files|*.*';
  122.          FilterIndex := 1;
  123.          if execute then
  124.             TrmCustomDataStorage(Component).WriteToFile(filename);
  125.       finally
  126.          free;
  127.       end
  128.    end;
  129. end;
  130.  
  131. end.
  132.