Difference between revisions of "TXMLPropStorage"

From Lazarus wiki
Jump to navigationJump to search
m (Fixed syntax highlighting; deleted category included in page template)
(14 intermediate revisions by 10 users not shown)
Line 1: Line 1:
 
{{TXMLPropStorage}}
 
{{TXMLPropStorage}}
  
== Introduction ==
+
'''TXMLPropStorage''' [[image:txmlpropstorage.png]] is a component to save and restore selected properties (either [[TForm]] or any control on it). It works with the TForm.SessionProperties property. It's available on [[Misc tab]] of the [[Component Palette]].
  
TXMLPropStorage is a component to save and restore selected properties (either TForm or any control on it). It's work with TForm.[[doc:lcl/forms/tform.sessionproperties.html|SessionProperties]] property. It's available on '''Misc''' tab of component palette.
+
== Usage ==
  
== Usage ==
+
# Drop a TXMLPropStorage component on form and set filename property, for example: session.xml
# Drop a [[doc:lcl/xmlpropstorage/txmlpropstorage.html|TXMLPropStorage]] component on form and set filename property, for example: session.xml
 
 
# Select form, go to Object Inspector and open editor window for the [[doc:lcl/forms/tform.sessionproperties.html|SessionProperties]] property of TForm.
 
# Select form, go to Object Inspector and open editor window for the [[doc:lcl/forms/tform.sessionproperties.html|SessionProperties]] property of TForm.
 
# Add here properties of form and/or controls to be stored inside session.xml (example: width;height).
 
# Add here properties of form and/or controls to be stored inside session.xml (example: width;height).
Line 16: Line 15:
  
 
== StoredValues property ==
 
== StoredValues property ==
TINIPropStorage and TXMLPropStorage has a ''StoredValues'' property which stores some value (it's useful to uses no others configs file)...
 
  
* Why is this really util?
+
[[TINIPropStorage]] and TXMLPropStorage have a ''StoredValues'' property which stores some value (it's useful to use no other config file).
*# Some properties (as CheckGroup.Item[n].Checked) cannot be saved in SessionProperties of TForm, then you need do this manually. It's useful to save others settings informations too.
+
 
 +
Some properties (as CheckGroup.Item[n].Checked) cannot be saved in SessionProperties of TForm, you need to do this manually. It's useful to save other setting information too.
  
 
Let's write a simple demo:
 
Let's write a simple demo:
Line 28: Line 27:
 
* Click in XMLPropStorage1 and access StoredValues property editor;
 
* Click in XMLPropStorage1 and access StoredValues property editor;
 
* Add a new value with name = item0_checked and value = -1 (True = -1);
 
* Add a new value with name = item0_checked and value = -1 (True = -1);
* In OnShow event add this code:
+
* In the OnRestoreProperties event add this code:
<delphi>CheckGroup1.Checked[0] := StrToBool(XMLPropStorage1.StoredValue['item0_checked']);</delphi>
+
 
 +
<syntaxhighlight lang=pascal>
 +
CheckGroup1.Checked[0] := StrToBool(XMLPropStorage1.StoredValue['item0_checked']);
 +
</syntaxhighlight>
  
* In OnClose event add this code:
+
* In the OnSavingProperties event add this code:
<delphi>XMLPropStorage1.StoredValue['item0_checked'] := BoolToStr(CheckGroup1.Checked[0]);</delphi>
+
 
 +
<syntaxhighlight lang=pascal>
 +
XMLPropStorage1.StoredValue['item0_checked'] := BoolToStr(CheckGroup1.Checked[0]);
 +
</syntaxhighlight>
  
 
* Run the demo program, change checked property of TCheckGroup.Items[n] and close form. Your changes was saved? :)
 
* Run the demo program, change checked property of TCheckGroup.Items[n] and close form. Your changes was saved? :)
 
 
You can change ''Key'' property of StoredValues.Items[n] if you're saving some information confidential (it uses XOREncode and XORDecode functions of RTL on saving and restoring routines).
 
You can change ''Key'' property of StoredValues.Items[n] if you're saving some information confidential (it uses XOREncode and XORDecode functions of RTL on saving and restoring routines).
  
Line 41: Line 45:
  
 
TXMLPropStorage has a default handler if you don't set a filename.
 
TXMLPropStorage has a default handler if you don't set a filename.
Under Windows/MacOS the settings will be saved in the application directory as PROGRAMNAME.xml.
+
Under Windows the settings will be saved in the application directory as PROGRAMNAME.xml.
  
Under Unix likes it will be saved in the home directory of the current user as .PROGRAMNAME
+
Under Unix/Linux/macOS it will be saved in the home directory of the current user as .PROGRAMNAME
  
 
It is therefore a very good idea to leave the filename blank for unix programs meant to be run by normal users.
 
It is therefore a very good idea to leave the filename blank for unix programs meant to be run by normal users.
  
According to bug report [http://bugs.freepascal.org/view.php?id=13949 13949, note 28856]: "The StoredValues[] array can only be used during the OnRestoreProperties or OnSaveProperties events. Outside these events, the values will not be stored." and "If you want to save/load values that are not published properties of a component or control, you should save them in a OnSaveProperties event, and
+
According to bug report [http://bugs.freepascal.org/view.php?id=13949 13949, note 28856]: "The StoredValues[] array can only be used during the OnRestoreProperties or OnSaveProperties events. Outside these events, the values will not be stored." and "If you want to save/load values that are not published properties of a component or control, you should save them in a OnSaveProperties event, and load them using the OnRestoreProperties event."
load them using the OnRestoreProperties event."
 
  
 
== See also ==
 
== See also ==
  
[[Hardware Access]]
+
* [[doc:lcl/xmlpropstorage/txmlpropstorage.html|TXMLPropStorage doc]]
 +
* [[doc:lcl/forms/tform.sessionproperties.html|SessionProperties doc]]
 +
* [[Hardware Access]]
  
[[Category:Components]]
+
{{LCL Components}}

Revision as of 02:24, 2 March 2020

Deutsch (de) English (en) español (es) français (fr) polski (pl) português (pt) русский (ru)

TXMLPropStorage txmlpropstorage.png is a component to save and restore selected properties (either TForm or any control on it). It works with the TForm.SessionProperties property. It's available on Misc tab of the Component Palette.

Usage

  1. Drop a TXMLPropStorage component on form and set filename property, for example: session.xml
  2. Select form, go to Object Inspector and open editor window for the SessionProperties property of TForm.
  3. Add here properties of form and/or controls to be stored inside session.xml (example: width;height).
  4. Compile the application.

Your application now will read selected property value from session.xml and apply it on runtime (like Width, Height, Left, Top for TForm).

TINIPropStorage component works the same way as TXMLPropStorage, except it stores the session information in an IniFile.

StoredValues property

TINIPropStorage and TXMLPropStorage have a StoredValues property which stores some value (it's useful to use no other config file).

Some properties (as CheckGroup.Item[n].Checked) cannot be saved in SessionProperties of TForm, you need to do this manually. It's useful to save other setting information too.

Let's write a simple demo:

  • Run Lazarus and start a new application;
  • Drop a TXMLPropStorage and TCheckGroup component;
  • Add one item in TCheckGroup (Item Test);
  • Click in XMLPropStorage1 and access StoredValues property editor;
  • Add a new value with name = item0_checked and value = -1 (True = -1);
  • In the OnRestoreProperties event add this code:
CheckGroup1.Checked[0] := StrToBool(XMLPropStorage1.StoredValue['item0_checked']);
  • In the OnSavingProperties event add this code:
XMLPropStorage1.StoredValue['item0_checked'] := BoolToStr(CheckGroup1.Checked[0]);
  • Run the demo program, change checked property of TCheckGroup.Items[n] and close form. Your changes was saved? :)

You can change Key property of StoredValues.Items[n] if you're saving some information confidential (it uses XOREncode and XORDecode functions of RTL on saving and restoring routines).

Notes

TXMLPropStorage has a default handler if you don't set a filename. Under Windows the settings will be saved in the application directory as PROGRAMNAME.xml.

Under Unix/Linux/macOS it will be saved in the home directory of the current user as .PROGRAMNAME

It is therefore a very good idea to leave the filename blank for unix programs meant to be run by normal users.

According to bug report 13949, note 28856: "The StoredValues[] array can only be used during the OnRestoreProperties or OnSaveProperties events. Outside these events, the values will not be stored." and "If you want to save/load values that are not published properties of a component or control, you should save them in a OnSaveProperties event, and load them using the OnRestoreProperties event."

See also


LCL Components
Component Tab Components
Standard TMainMenu • TPopupMenu • TButton • TLabel • TEdit • TMemo • TToggleBox • TCheckBox • TRadioButton • TListBox • TComboBox • TScrollBar • TGroupBox • TRadioGroup • TCheckGroup • TPanel • TFrame • TActionList
Additional TBitBtn • TSpeedButton • TStaticText • TImage • TShape • TBevel • TPaintBox • TNotebook • TLabeledEdit • TSplitter • TTrayIcon • TControlBar • TFlowPanel • TMaskEdit • TCheckListBox • TScrollBox • TApplicationProperties • TStringGrid • TDrawGrid • TPairSplitter • TColorBox • TColorListBox • TValueListEditor
Common Controls TTrackBar • TProgressBar • TTreeView • TListView • TStatusBar • TToolBar • TCoolBar • TUpDown • TPageControl • TTabControl • THeaderControl • TImageList • TPopupNotifier • TDateTimePicker
Dialogs TOpenDialog • TSaveDialog • TSelectDirectoryDialog • TColorDialog • TFontDialog • TFindDialog • TReplaceDialog • TTaskDialog • TOpenPictureDialog • TSavePictureDialog • TCalendarDialog • TCalculatorDialog • TPrinterSetupDialog • TPrintDialog • TPageSetupDialog
Data Controls TDBNavigator • TDBText • TDBEdit • TDBMemo • TDBImage • TDBListBox • TDBLookupListBox • TDBComboBox • TDBLookupComboBox • TDBCheckBox • TDBRadioGroup • TDBCalendar • TDBGroupBox • TDBGrid • TDBDateTimePicker
Data Access TDataSource • TCSVDataSet • TSdfDataSet • TBufDataset • TFixedFormatDataSet • TDbf • TMemDataset
System TTimer • TIdleTimer • TLazComponentQueue • THTMLHelpDatabase • THTMLBrowserHelpViewer • TAsyncProcess • TProcessUTF8 • TProcess • TSimpleIPCClient • TSimpleIPCServer • TXMLConfig • TEventLog • TServiceManager • TCHMHelpDatabase • TLHelpConnector
Misc TColorButton • TSpinEdit • TFloatSpinEdit • TArrow • TCalendar • TEditButton • TFileNameEdit • TDirectoryEdit • TDateEdit • TTimeEdit • TCalcEdit • TFileListBox • TFilterComboBox • TComboBoxEx • TCheckComboBox • TButtonPanel • TShellTreeView • TShellListView • TXMLPropStorage • TINIPropStorage • TJSONPropStorage • TIDEDialogLayoutStorage • TMRUManager • TStrHolder
LazControls TCheckBoxThemed • TDividerBevel • TExtendedNotebook • TListFilterEdit • TListViewFilterEdit • TLvlGraphControl • TShortPathEdit • TSpinEditEx • TFloatSpinEditEx • TTreeFilterEdit • TExtendedTabControl •
RTTI TTIEdit • TTIComboBox • TTIButton • TTICheckBox • TTILabel • TTIGroupBox • TTIRadioGroup • TTICheckGroup • TTICheckListBox • TTIListBox • TTIMemo • TTICalendar • TTIImage • TTIFloatSpinEdit • TTISpinEdit • TTITrackBar • TTIProgressBar • TTIMaskEdit • TTIColorButton • TMultiPropertyLink • TTIPropertyGrid • TTIGrid
SQLdb TSQLQuery • TSQLTransaction • TSQLScript • TSQLConnector • TMSSQLConnection • TSybaseConnection • TPQConnection • TPQTEventMonitor • TOracleConnection • TODBCConnection • TMySQL40Connection • TMySQL41Connection • TMySQL50Connection • TMySQL51Connection • TMySQL55Connection • TMySQL56Connection • TMySQL57Connection • TSQLite3Connection • TIBConnection • TFBAdmin • TFBEventMonitor • TSQLDBLibraryLoader
Pascal Script TPSScript • TPSScriptDebugger • TPSDllPlugin • TPSImport_Classes • TPSImport_DateUtils • TPSImport_ComObj • TPSImport_DB • TPSImport_Forms • TPSImport_Controls • TPSImport_StdCtrls • TPSCustomPlugin
SynEdit TSynEdit • TSynCompletion • TSynAutoComplete • TSynMacroRecorder • TSynExporterHTML • TSynPluginSyncroEdit • TSynPasSyn • TSynFreePascalSyn • TSynCppSyn • TSynJavaSyn • TSynPerlSyn • TSynHTMLSyn • TSynXMLSyn • TSynLFMSyn • TSynDiffSyn • TSynUNIXShellScriptSyn • TSynCssSyn • TSynPHPSyn • TSynTeXSyn • TSynSQLSyn • TSynPythonSyn • TSynVBSyn • TSynAnySyn • TSynMultiSyn • TSynBatSyn • TSynIniSyn • TSynPoSyn
Chart TChart • TListChartSource • TRandomChartSource • TUserDefinedChartSource • TCalculatedChartSource • TDbChartSource • TChartToolset • TChartAxisTransformations • TChartStyles • TChartLegendPanel • TChartNavScrollBar • TChartNavPanel • TIntervalChartSource • TDateTimeIntervalChartSource • TChartListBox • TChartExtentLink • TChartImageList
IPro TIpFileDataProvider • TIpHtmlDataProvider • TIpHttpDataProvider • TIpHtmlPanel
Virtual Controls TVirtualDrawTree • TVirtualStringTree • TVTHeaderPopupMenu