Getting information about variables
This section has code fragments illustrating how to get information
about variables from a ClassDefinition object called cd_windef.
For examples of assigning a value to cd_windef,
see “Getting a class definition
object”.
List of variables
Variables associated with a class are listed in the VariableList
array of the ClassDefinition object. When you examine that array, you
find not only variables you have defined explicitly but also PowerBuilder object
properties and nested objects, which are instance variables.
This example loops through the VariableList array and builds
a list of variable names. PowerBuilder properties appear first,
followed by nested objects and your own instance and shared variables:
1 |
string s, lineend<br>integer li<br>VariableDefinition vard<br>lineend = "~r~n"<br> <br>FOR li = 1 to UpperBound(cd_windef.VariableList)<br>   vard = cd_windef.VariableList[li]<br>   s = s + vard.Name + lineend<br>NEXT<br>mle_1.Text = s |
Details about variables
This example looks at the properties of each variable in the
VariableList array and reports its datatype, cardinality, and whether
it is global, shared, or instance. It also checks whether an instance
variable overrides an ancestor declaration:
1 |
string s<br>integer li<br>VariableDefinition vard<br>lineend = "~r~n"<br> <br>FOR li = 1 to UpperBound(cd_windef.VariableList)<br>   vard = cd_windef.VariableList[li]<br>   s = s + vard.Name + ", "<br>   s = s + vard.TypeInfo.DataTypeOf<br> <br>   CHOOSE CASE vard.Cardinality.Cardinality<br>   CASE ScalarType!<br>      s = s + ", scalar"<br>   CASE UnboundedArray!, BoundedArray!<br>      s = s + ", array"<br>   END CHOOSE<br> <br>   CHOOSE CASE vard.Kind<br>   CASE VariableGlobal!<br>      s = s + ", global"<br>   CASE VariableShared!<br>      s = s + ", shared"<br>   CASE VariableInstance!<br>      s = s + ", instance"<br>      IF vard.OverridesAncestorValue = TRUE THEN<br>         s = s + ", override"<br>      END IF<br>   END CHOOSE<br>      s = s + lineend<br>NEXT<br>mle_1.text = s |