Property Saver - automatize saving of user settings

Property Saver is set of non visual components which allows you to centralize and automatize saving and restoring of windows position, properties of visual or non visual components and any other user defined values. Benefits:

  • it works without line of code (for standard components)
  • it's complex but very small solutions without any additional library
  • it's easy to extend to save properties of another non standard components
  • it improves your application and increase customer satisfaction

Property Saver support storing of forms and standard components settings without line of code (TForm, TEdit, TMemo, TListBox, TComboBox, TRadioButton, TRadioGroup, TCheckBox, TMenuItem). Other components can be managed by already created descendant components (TGridsPropSave, TDBGridPropSave) or you can create very easily your own component supporting any type of components (TMS, 3rd party...). Any other values can be saved manually by events OnReadProperties and OnSaveProperties.

All settings are stored in INI file. Its name can be set up at runtime, so it's very easy to use this package in multi user application, when each user use the same program but with his own INI file and therefore with his own configuration.

Pack contains:

  • TPropSaveFile - interface components between INI file and application
  • TPropSaveMain - main components providing all functions
  • TGridsPropSave, TDBGridPropsSave ...- descendant components for Grids, DBGrids etc.

Example of using

Step 1 - save main form position

  • Create new application with main form, Name=Form1
  • Place TPropSaveFile component on Form1, Name=PropSaveFile1
  • Place TPropSaveMain component on Form1, Name=PropSaveMain1
  • Set property PropSaveFile of PropSaveMain1: PropSaveFile=PropSaveFile1
  • Save and Run application

Now Form1 is always displayed in the same position as was when application finished.

Step 2 - save another form position

  • Create new form, Name=Form2
  • Add Form1 to uses part of Form2
  • Place TPropSaveMain component on Form2, Name=PropSaveMain2
  • Set property PropSaveFile of PropSaveMain2: PropSaveFile=Form1.PropSaveFile1
  • Add Button to Form1 and show Form2 on Click
  • Save and Run application

Now Form1 and Form2 is always displayed in the same position as was when application finished.

Step 3 - save standard components position and properties

  • Place TPanel to Form1, Name=Panel1
  • Set Align properties of Panel1, Align=alLeft
  • Add TSplitter to Form1, Name=Splitter1, Align=alLeft
  • Place another TPanel to Form1, Name=Panel2
  • Set Align properties of Panel2, Align=alClient
  • Place some other components to Panel1 and Panel2 (TEdit, TMemo, TCheckBox, TComboBox, TListBox)
  • DoubleClick on PropSaveMain1 component to display design time editor
  • In Tab "StdCtrl" select which components will be saved for saving of values of component, select all components
  • In Tab "CtrlPosition" select which components will be saved for saving of position of component, select Panel1
  • Save and Run application

Now all selected components is displayed with the same values as was when application finished. Additionally Panel1 is displayed in the same width.

The same steps use for each form in application.

Step 4 - save nonstandard components

  • Place TStringGrid component on Form2, Name=StringGrid2
  • Set property Options of StringGrid2: goEditing=True; goColSizing=true
  • Add TGridsPropSave to Form2, Name=GridsPropSave2
  • Set property PropSaveMain of GridsPropSave2, PropSaveMain=PropSaveMain2
  • DoubleClick on GridsPropSave2 component to display design time editor
  • Select which components will be saved, i.e. GridsPropSave2
  • Save and Run application

Now GridsPropSave2 is always displayed in the same content and columns width as was when application finished.

The same steps use for another components, but with another type of TCustomPropSave, i.e. TDBGridPropSave for saving of DBGrid properties.

Step 5 - save and read of user defined values

  • Open OnSaveProperties of PropSaveMain1 and add code:
    PSFile.WriteString(Key,'LastFile',SomeVariable);
  • Open OnReadProperties of PropSaveMain1 and add code:
    SomeVariable:=PSFile.ReadString(Key,'LastFile','noname.ini');

Now value of SomeVariable will be stored and restored automatically in INI file.

Step 6 - reset to default values

All settings are stored in one INI file, by default it is in directory with application and has name "appname.ini". For resetting from application use following code:
PropSaveFile1.Clear; // clear contents of ini file
PropSaveFile1.SaveFile(''); // save empty file
PropSaveFile1.DisableAll:=true; // don't save properties until close app
ShowMessage('Close the application and run again with default values.'); // inform user

Step 7 - change ini file name

For changing INI file name (e.g. according login name) use following:
  • Set property PropSaveEvents of PropSaveMain1, PropSaveEvents=pseFormShowHide (to be able to change filename before loading of main form values, another solution is to place TPropSaveFile to some DataModule and change filename before loading of Form1
  • Open OnCreate Events of Form1 and add code:
    PropSaveFile1.LoadFile('c:\user1.cfg');

Now all setting will be stored and restored in selected file (e.g. c:\user1.cfg).

Step 8 - create new PropSave component for saving properties of another type of components

For automatic re/storing of another components create new PropSave Components.
  • Use TCustomPropSave as parent component
  • Override two procedures
    protected
      procedure ReadSaveProps(A: TPropSaveAction; PSFile: TPropSaveFile; Key: string; Comp: TComponent); override;
    public
      function CanSave(Comp: TComponent): boolean; override;

See GridsPropSave.pas file for example.

Go back

RosiComp package

 
 
Order online
Price: $ 35
includes full source code and free updates for one year
 
Order now
 
Version info
Version: 10.011 new
for Delphi 2010,XE,XE2,XE3,XE4,XE5
Last update: Nov 2013
 
RosiComps is placed on Torry's page too.
Torry's Delphi pages