Kopia wikimirror

To jest mirror wiki z pascal.chat. Edycja, historia i logowanie są tam.

TXMLPropStorage/pl

Deutsch · English · Español · Français · Polski · Português · Русский

TXMLPropStorage 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 palecie komponentów.

Użycie

  1. Upuść TXMLPropStorage na formularzu i ustaw nazwę pliku we właściwościach, na przykład: session.xml
  2. Wybierz formularz, przejdź do Inspektora obiektów i otwórz okno edytora dla właściwości SessionProperties w TForm.
  3. Dodaj tutaj właściwości formularza i/lub kontrolek, które mają być przechowywane w pliku session.xml (np.: szerokość; wysokość).
  4. Skompiluj aplikację.

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).

Komponent TINIPropStorage działa tak samo jak TXMLPropStorage, z wyjątkiem tego, że przechowuje informacje o sesji w 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:

pascal
CheckGroup1.Checked[0] := StrToBool(XMLPropStorage1.StoredValue['item0_checked']);
pascal
XMLPropStorage1.StoredValue['item0_checked'] := BoolToStr(CheckGroup1.Checked[0]);

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


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.

Wersja 1, ostatnia zmiana: WikiArchive, .