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 PocketBuilder object properties and nested objects, which are instance variables.
This example loops through the VariableList array and builds a list of variable names. PocketBuilder properties appear first, followed by nested objects and your own instance and shared variables:
string s, lineend integer li VariableDefinition vard lineend = "~r~n" FOR li = 1 to UpperBound(cd_windef.VariableList) vard = cd_windef.VariableList[li] s = s + vard.Name + lineend NEXT mle_1.Text = s
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:
string s integer li VariableDefinition vard lineend = "~r~n" FOR li = 1 to UpperBound(cd_windef.VariableList) vard = cd_windef.VariableList[li] s = s + vard.Name + ", " s = s + vard.TypeInfo.DataTypeOf CHOOSE CASE vard.Cardinality.Cardinality CASE ScalarType! s = s + ", scalar" CASE UnboundedArray!, BoundedArray! s = s + ", array" END CHOOSE CHOOSE CASE vard.Kind CASE VariableGlobal! s = s + ", global" CASE VariableShared! s = s + ", shared" CASE VariableInstance! s = s + ", instance" IF vard.OverridesAncestorValue = TRUE THEN s = s + ", override" END IF END CHOOSE s = s + lineend NEXT mle_1.text = s