Logo
Development of Delphi components and applications   

Property saver package - 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.


Back
Contact:
Tomas Rosinsky
Czech Republic
e-mail: delphi@rosinsky.cz
All products are for Microsoft Windows
Components are tested with Delphi 6,7, 2005, 2006, 2007, 2009 and 2010
Number of visitors:
Your order will be processed by:
BMT Micro