Referencing structures

When you define a structure, you are defining a new datatype. You can use this new datatype in scripts and user-defined functions as long as the structure definition is stored in a library in the application's library search path.

StepsTo use a structure in a script or user-defined function:

  1. Declare a variable of the structure type.

  2. Reference the variable in the structure.

Referencing global structures

The variables in a structure are similar to the properties of a PocketBuilder object. To reference a global structure's variable, use dot notation:

structure.variable

Example Assume that s_empdata is a global structure with the variables emp_id, emp_dept, emp_fname, emp_lname, and emp_salary. To use this structure definition, declare a variable of type s_empdata and use dot notation to reference the structure's variables, as shown in the following script:

s_empdata   lstr_emp1, lstr_emp2 // Declare 2 variables
                                 // of type emp_data.

lstr_emp1.emp_id = 100       // Assign values to the
lstr_emp1.emp_dept = 200     // structure variables.
lstr_emp1.emp_fname = "John"
lstr_emp1.emp_lname = "Paul-Jones"
lstr_emp1.emp_salary = 99908.23

// Retrieve the value of a structure variable.
lstr_emp2.emp_salary = lstr_emp1.emp_salary * 1.05

// Use a structure variable in a
// PowerScript function.
MessageBox ("New Salary", &
   String(lstr_emp2.emp_salary,"$###,##0.00"))

Referencing object-level structures

You reference object-level structures in scripts for the object itself exactly as you do global structures. Declare a variable of the structure type, then use dot notation:

structure.variable

Example Assume that the structure str_custdata is defined for the window w_history and you are writing a script for a CommandButton in the window. To use the structure definition in the script, write:

str_custdata lstr_cust1
lstr_cust1.name = "Joe"

NoteNo access to object-level structures outside the object You cannot make object-level structures accessible outside an object because object-level structures are implicitly private.