Xbasic

# PROPERTY_TO_STRING Function

Syntax

String as C = PROPERTY_TO_STRING(P source[,N limit])

Arguments

source

The name of a dot variable.

limit

Numeric

Description

Dump pointer contents (can be variable frame) to a string - (impose optional limit on length of leaf data).

Discussion

The PROPERTY_TO_STRING() function converts a "dot" variable to a string. Dot_Variable is the dot variable's root name. The dot variable can be of arbitrary complexity. Once a dot variable has been converted to a string, it is easy to save the string, in effect, saving the current values of all of the dot variable's sub-elements. The PROPERTY_FROM_STRING()function allows you to restore a dot variable and all of its sub-elements from a string that was previously created using PROPERTY_TO_STRING(). For example, assume that you have this "dot" variable:

put description here

dim p as P
p.lastname = "smith"
p.firstname = "john"
str = property_to_string(p)

If you examine the contents of the str variable, you see the following string:

<lastname = "smith">
<firstname = "john">

The above example is fairly trivial. Consider the case of a more complex dot variable:

dim f as P
dim f.family[3] as P
dim f.family[1].kids[3] as P
dim f.family[2].kids[3] as P
f.Family[1].father = "John"
f.Family[1].mother = "Joan"
f.Family[1].kids[1].NAME = "Sammy"
f.Family[1].kids[1].age = 4
f.Family[1].kids[2].NAME = "Sonia"
f.Family[1].kids[2].age = 3
f.Family[1].kids[3].NAME = "Samantha"
f.Family[1].kids[3].age = 2
f.Family[2].father = "Andrew"
f.Family[2].mother = "Andrea"
f.Family[2].kids[2].NAME = "Cloe"
f.Family[2].kids[2].age = 14
f.Family[2].kids[2].NAME = "Colin"
f.Family[2].kids[2].age = 13
str = property_to_string(f)

In this case, if you examine the 'str' variable, you will see the following string:

<family<[1]<father = "John">
<mother = "Joan">
<kids<[1]<name = "Sammy">
<age = 4>
>
<[2]<name = "Sonia">
<age = 3>
>
<[3]<name = "Samantha">
<age = 2>
>
>
>
<[2]<father = "Andrew">
<mother = "Andrea">
<kids<[1]>
<[2]<name = "Colin">
<age = 13>
>
<[3]>
>
>
<[3]>
>

### Example

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

Convert the elements of a dot variable to a string, then save the string to a file so that the values of the dot variables can be preserved.

dim p as P
p.lastname = "smith"
p.firstname = "john"
str = property_to_string(p)
'save the string to a file
save_TO_FILE(str,"c:\mydata\dot_variables.txt")