Sign in Join
Wiki copytemporary

TXMLPropStorage/pl: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: TXMLPropStorage/pl

OldNewLine
1+**TXMLPropStorage** ![](/wiki-images/b/bf/Txmlpropstorage.png) jest składnikiem służącym do zapisywania i przywracania wybranych właściwości (TForm lub dowolnej kontrolki). Działa z właściwością TForm.SessionProperties. Jest dostępny w zakładce [[Misc tab]] na [[Component Palette|palecie komponentów]].
2+
3+## Użycie
4+
5+1. Upuść TXMLPropStorage na formularzu i ustaw nazwę pliku we właściwościach, na przykład: session.xml
6+2. Wybierz formularz, przejdź do Inspektora obiektów i otwórz okno edytora dla właściwości [[doc:lcl/forms/tform.sessionproperties.html|SessionProperties]] w TForm.
7+3. Dodaj tutaj właściwości formularza i/lub kontrolek, które mają być przechowywane w pliku session.xml (np.: szerokość; wysokość).
8+4. Skompiluj aplikację.
9+
10+Twoja aplikacja odczyta teraz wybraną wartość właściwości z session.xml i zastosuje ją w czasie wykonywania (np. Width, Height, Left, Top dla TForm).
11+
12+Komponent TINIPropStorage działa tak samo jak TXMLPropStorage, z wyjątkiem tego, że przechowuje informacje o sesji w [IniFile](http://lazarus-ccr.sourceforge.net/docs/fcl/inifiles/index.html).
13+
14+## StoredValues property
15+
16+[[TINIPropStorage]] and TXMLPropStorage have a *StoredValues* property which stores some value (it's useful to use no other config file).
17+
18+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.
19+
20+Let's write a simple demo:
21+
22+- Run Lazarus and start a new application;
23+- Drop a TXMLPropStorage and TCheckGroup component;
24+- Add one item in TCheckGroup (Item Test);
25+- Click in XMLPropStorage1 and access StoredValues property editor;
26+- Add a new value with name = item0_checked and value = -1 (True = -1);
27+- In the OnRestoreProperties event add this code:
28+
29+``` pascal
30+CheckGroup1.Checked[0] := StrToBool(XMLPropStorage1.StoredValue['item0_checked']);
31+```
32+
33+- In the OnSavingProperties event add this code:
34+
35+``` pascal
36+XMLPropStorage1.StoredValue['item0_checked'] := BoolToStr(CheckGroup1.Checked[0]);
37+```
38+
39+- Run the demo program, change checked property of TCheckGroup.Items\[n\] and close form. Your changes was saved? :)
40+
41+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).
42+
43+## Notes
44+
45+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.
46+
47+Under Unix/Linux/macOS it will be saved in the home directory of the current user as .PROGRAMNAME
48+
49+It is therefore a very good idea to leave the filename blank for unix programs meant to be run by normal users.
50+
51+According to bug report [13949, note 28856](http://bugs.freepascal.org/view.php?id=13949): "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."
52+
53+## See also
54+
55+- [[doc:lcl/xmlpropstorage/txmlpropstorage.html|TXMLPropStorage doc]]
56+- [[doc:lcl/forms/tform.sessionproperties.html|SessionProperties doc]]
57+- [[Hardware Access]]
58+
59+---
60+*From the Free Pascal wiki, page "TXMLPropStorage/pl", as it stood on 2020-10-29 after a change by Slawek, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history