The dot variable to populate.
A text string that was originally created using the PROPERTY_TO_STRING() function
Specifications for formatting the data. Refer to the <ARRAY>.INITIALIZE_PROPERTIES() method.
Recover previously dumped contents back into a pointer, format allows for optional user spec.
The PROPERTY_FROM_STRING() function initializes the values in a "dot" variable referenced by Dot_Variable. Property_String is a text string that was originally created using the PROPERTY_TO_STRING()function, and it contains the value of each sub-element of the dot variable. (If the optional Format_String is specified, then Property_String has a different format. See below.)
Before you initialize variables using PROPERTY_FROM_STRING() , at least one of the dot variables sub-elements must be initialized. For example, assume that you want to initialize a dot variable called "p2". Before the PROPERTY_FROM_STRING() function is used you must execute this Xbasic:
'Declare the dot variable dim P2 as P 'Initialize a dot variable sub-element. P2.dummy = ""
Having done this, you can now call the PROPERTY_FROM_STRING() function. For example (Assume that str was previously created using the PROPERTY_TO_STRING() function):
dim p as P p.dummy = "" property_from_string(p, str)
Specifying a Format String
If the optional Format_String parameter is specified, then string must be in the format specified in the Format_String. The syntax of the Format_String is the same as is used in the <ARRAY>.INITIALIZE_PROPERTIES()method.
data = "Fred|Smith|46" format = "first_name:c|last_name:c|age:N" dim p as P p.dummy = "" property_from_string(p, data, format) ? p = age = 46.000000 dummy = "" first_name = "Fred" last_name = "Smith"
This example convert the contents of a record to a string, then writes them out in a duplicate record.
dim t as P dim t2 as P dim str as C t = table.open("customer") t.fetch_goto(targetRecord) str = property_to_string(t) t2 = table.open("customer") t2.enter_begin() property_from_string(t2,str) t2.enter_end(.t.) t.close() t2.close()
The following is an Interactive Window session:
dim p as P p.first_name = "Fred" p.last_name = "Smith" str = property_to_string(p) ? str = <first_name="Fred"> <last_name="Smith"> delete p ? p ERROR: p not found. dim p as P 'Initialize any variable as a sub-element of p p.first_name = "" property_from_string(p, str) ? p = first_name = "Fred" last_name = "Smith"
Copying a Complex Pointer Variable
Follow this procedure if you need to copy a complex pointer variable.
' create the initial pointer variable with any set of elements dim x as P dim x.name as C dim x.phone as C dim x.data[2,2,2] as C x.data[1,1,1] = "A" x.data[1,1,2] = "B" x.data[1,2,1] = "C" x.data[1,2,2] = "D" x.data[2,1,1] = "E" x.data[2,1,2] = "F" x.data[2,2,1] = "G" x.data[2,2,2] = "H" ' create the duplicate pointer variable ' explicitly dimension arrays dim y as P dim y.data[2,2,2] as C property_from_string(y, property_to_string(x)) ? y = name = "" phone = "" ? y.data = [1,1,1] = "A" [1,1,2] = "B" [1,2,1] = "C" [1,2,2] = "D" [2,1,1] = "E" [2,1,2] = "F" [2,2,1] = "G" [2,2,2] = "H"
Copying Data Between Tables with Different Structures
Follow this procedure to copy data between tables with different structures.
dim t1 as P dim t2 as P t1 = table.open("sourcetable") t2 = table.open("targettable") t2.enter_begin() property_from_string(t2, property_to_string(t1)) t2.enter_end(.t.) t1.close() t2.close()