PROPERTY_FROM_STRING()

Syntax

PROPERTY_FROM_STRING( Dot_Variable as P, Property_String as C [, Format_String as C [, Truncate as C ] ] )

Argument

 

Description

Dot_Variable

V5

The name of a dot variable.

Property_String

V5

A text string that was originally created using the PROPERTY_TO_STRING()function.

Format_String

V5

Optional. Specifications for formatting the data. Refer to the <ARRAY>.INITIALIZE_PROPERTIES()method.

Truncate

V6

Optional. Default = "". Useful when the data should be trimmed to match smaller array dimensions.

  • "" = Resize array to match data dimensions.

  • "T" = Trim input to match array dimensions.

Description

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

Supported By

Alpha Five Version 5 and Above

Examples

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.

For example:

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"

Examples

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)

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(str, p)

? p.first_name -> "Fred"

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

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

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

See Also

Variable Functions and Methods, PROPERTY_TO_STRING()