PropExchange Object
Description
The PropExchange object is used for reading and writing Flow Graph layout information to/from an XML file, the registry, or a binary file.
For a list of all members defined in this module, see PropExchange Members.
Remarks
The PropExchange object provides a universal solution to save the layout and state of the Flow Graph to a single file or the system registry, with support to write/load directly to/from a file or registry.
In addition to saving the layout and state of the controls, additional String and Integer values can be saved to the same file using the ExchangeInt and ExchangeString methods. It is important to note that both methods require a variable reference to store the data.
Note: When working with XML data, there cannot be any spaces in the name given to the data.
More than one layout for each object can be saved to the same file. This allows multiple layouts to be saved to a single location. The GetSection method will create a new "section" in the file/registry in which a new layout can be saved/loaded.
There are three ways to save and load layout/state information to a PropExchange object:
- Load and save information to the system registry.
- Load and save information to an XML file.
- Load and save information to a binary file.
The CreateAsBinary, CreateAsRegistry, and CreateAsXML methods are used to specify whether to save or load the layout/state information and the location of the layout/state information (path to XML or Bin file, Registry Key).
Note: This does not actually load/save the information; it just indicates the location to load/save the information to/from and if it will be loaded/saved.
When using any of the CreateAs methods, the Loading parameter is used to specify whether the layout information is currently Loading or saving. The Loading property will be True until set to False by calling a CreateAs method and passing False as the Loading parameter. The Loading property can be used to determine if you are currently loading layout information.
The DoPropExchange method is used to actually load or save the information to a file or the registry.
When saving information, the Valid property should be used after a call to one of the CreateAs methods to verify that the layout information was correctly saved to the PropExchange object.
When loading information, the LoadFromFile method can be used to verify and load the information at the same time.
The Encoding property is provided for Unicode support when working with XML files.
The Value property is used when working with XML data. The Value will always contain the layout and state of the control in XML format. The Value is intended to be used to manually create or get the layout in XML format. This can be used to manually read/write the layout information directly to/from the Value property if you don't want to save to a file.
Example
ExchangeInt and ExchangeString Sample (Visual Basic)
This sample illustrates how to use the ExchangeInt and ExchangeString methods to load and save a Long and String to/from a file.
Private Sub LoadData()
Dim pxRead As New PropExchange
' Specifies to load information from a node named "CustomerInformation"
pxRead.CreateAsXML True, "CustomerInformation"
' Specifies the name of the file to search for the "CustomerInformation" node.
If pxRead.LoadFromFile("c:\test.xml") Then
' Declares a String object to store information read from the test.xml file.
Dim StrName As String
StrName = ""
' Searches for a node named "CustomerName", if found, then the information
' will be stored in the StrName object.
pxRead.ExchangeString "CustomerName", StrName, ""
Debug.Print StrName
Dim IntAge As Long
IntAge = 0
pxRead.ExchangeInt "CustomerAge", IntAge, 0
Debug.Print IntAge
End If
End Sub
Private Sub SaveData()
Dim pxWrite As New PropExchange
' Specifies that a node named "CustomerInformation" will be created.
' The XML string is currently stored in the Value property of the pxWrite PropExchange object.
pxWrite.CreateAsXML False, "CustomerInformation"
' Verify that the "CustomerInformation" node was successfully written to the object.
If pxWrite.Valid Then
' Declare a String object to pass in as a reference to the ExchangeString method.
Dim StrName As String
StrName = "Mr. Smith"
' Important - There can be no spaces in the name of the node when using XML
' This will create a node named "CustomerName" under the "CustomerInformationNode"
pxWrite.ExchangeString "CustomerName", StrName, ""
Dim IntAge As Long
IntAge = 32
pxWrite.ExchangeInt "CustomerAge", IntAge, 0
' Writes the XML string stored in the Value property to an XML file named test.xml.
pxWrite.SaveToFile "c:\test.xml"
End If
End Sub
See Also
Copyright (c) 1998-2024 Codejock Technologies. All rights reserved.