Difference between revisions of "TXMLPropStorage/de"

From Free Pascal wiki
Jump to navigationJump to search
m (Reverted edits by Chronos (Talk); changed back to last version by Swen)
Line 52: Line 52:
  
 
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."
 
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."
 
[[Category:Components]]
 

Revision as of 14:12, 4 September 2010

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

Einleitung

TXMLPropStorage ist eine Komponente, um die ausgewählten Eigenschaften zu speichern / wiederherzustellen (entweder von TForm oder jedem Bedienelement darauf). Sie arbeitet mit der TForm.SessionProperties Eigenschaft. Zu finden ist sie auf dem Tab Misc in der Komponentenpalette.

Verwendung

  1. Legen sie eine TXMLPropStorage Komponente auf dem Formular ab und setzen die Dateinamen-Eigenschaft, zum Beispiel auf: session.xml
  2. Öffnen sie das Bearbeitungsfenster der SessionProperties Eigenschaft von TForm im Objektinspektor.
  3. Fügen sie hier Eigenschaften des Formulars und/oder Bedienelemente hinzu, um in session.xml gespeichert zu werden.
  4. Kompilieren sie die Anwendung.

Ihre Anwendung wird jetzt die ausgewählte Eigenschaft von session.xml lesen und zur Laufzeit anwenden (wie Width, Height, Left, Top für TForm).

TINIPropStorage funktioniert auf die selbe Weise wie TXMLPropStorage, ausgenommen daß sie die Sessioninformation in einer INI-Datei speichert.

StoredValues Eigenschaft

TINIPropStorage und TXMLPropStorage haben eine StoredValues Eigenschaft, welche einige Werte sichert (it's useful to uses no others configs file)...

  • Why is this really util?
    1. 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.

Let's write a simple demo:

  • Öffnen sie Lazarus und starten sie eine neue Anwendung;
  • Legen sie eine TXMLPropStorage und eine TCheckGroup Komponente auf dem Formular ab;
  • 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 OnShow event add this code:

<delphi> CheckGroup1.Checked[0] := StrToBool(XMLPropStorage1.StoredValue['item0_checked']); </delphi>

  • In OnClose event add this code:

<delphi> XMLPropStorage1.StoredValue['item0_checked'] := BoolToStr(CheckGroup1.Checked[0]); </delphi>

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

Anmerkungen

TXMLPropStorage hat einen Vorgabe-handler, wenn sie keinen Dateinamen festlegen. Unter Windows/MacOS werden die Einstellungen im Anwendungsverzeichnis als PROGRAMNAME.xml gespeichert.

Unter Unix-Systemen werden sie im home Verzeichnis des aktuellen Benutzers als .PROGRAMNAME gespeichert.

Es ist daher eine gute Idee, den Dateinamen leer zu lassen für Unix-Programme, die dazu bestimmt sind, durch normale Benutzer gestartet zu werden.

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