Delphi Sources
Components | Framework | Traybar utilities | DownLoads | thork@usa.net |  
Overview | TProtector | TPersistor | TFormBinder 

 

Components - TPeristor

TPersistor is a component that saves specified properties for specified component types to a file or the registry or to the component itself. No programming is required. A dialog box is available at design time to specify specify which proerties to save from which components. The same dialog box can be activated at run time with or without the "which properties" box to e.g. to allow field personell to modify the values of propeties. E.g to do in situ translation.

Below, the programmer has chosen to save Captions and Hints of every component that has these properties, and The Title property of TColumn. This takes care of storing different languages.

 

Possible uses  

  • Gloabalization. Switch between languages at run time or design time  
  • Persistence. Save contents of edit boxes, the states of check boxes, radiobuttons, and menu items, etc.  
  • Layout. Save the Windowstate of Forms, the Left, Top, Width, Height of Forms and Panels, Width of TColumn.  
  • Configuration and Access control. Save restore visibility/enabledness/readonly of menu items, panels, tabsheets, DBGrids, etc.    

Main features  

  • Specify which properties to store/retrieve for all descendants.  
  • Works with unknown components.
  • Storage can be file or registry based or the component it self.  
  • Path to storage can depend on formtype, formname, and form caption so that descendants and multiple instances don't get mixed up.  
  • Path to storage can depend on the Config property providing easy way to switch between e.g. different languages or access levels.    
  • Automatically traverses collections, such as TColumns.
  • Traverses specified subobjects, e.g. Items of TListBox or Columns of TDBGrid.
  • Control characters are quoted so that e.g. the Text property of TMemo or TListBox.Items is is saved and restored correctly.

Example  

You can use the Persistor to switch between languages at runtime or design time. Place a persistor on you form and specify that you want it to work with the Caption and the Hint properties of all components.  

This is done by assigning the following text to WhichProperties.    

TComponent=Hint,Caption   

Now you can save and restore the these properties at design time or run time. At run time you can call SaveToFile and LoadFromFile and at design time you can set the Command property to pcSaveToFile or pcLoadToFile. You can also use the property editor.  

The values of the properties can be saved in the regsitry or a file.

The registy or filepath can be specified in terms of the the formname, formtype, formcaption and the value of the config property. If you place your persistor on a ancestor form, you can use the constants "<Formname>" or "<Formtype>" to modify the path of the storage. E.g.    

c:\Program files\MyComp\MyAppl\Lang\<Formtype>.txt   

or    

\SOFTWARE\MyComp\MyAppl\Lang\Danish\<Formtype>.txt   

The Config property can be included in the pathname to flexibly switch between various configurations, such as languages or expert levels. E.g.:    

\SOFTWARE\MyComp\MyAppl\<Config>\<Formtype>.txt

When you call LoadFromFile or SaveTofile, <Config> will be replaced with the value of the Config string property.

.

 

 

 

 

Statistics