Referencing an object from its name¶
fromname() |
Reference an object from its name |
SYNTAX
fromname(object_name)
References an object from an alphanumeric field or text string containing the object’s name.
Parsing the name at run time is a relatively slow operation, so if more than one reference is to be made, it is recommended that a pointer is assigned to the object, as in the example below.
Since Sculptor 6.2.0:
Supports nested records and records with dimensions.
The subscripts can be other field values (no need to be literal values any more), like
fromname("fldArray[fldNumber]")
.
EXAMPLE
!temp PrintFuncPtr,,p
!temp PrintFuncName,,a20
!temp PrintMode,,a1
if (NormalPF->checked = TRUE) then PrintMode = "N"
if (CompPF->checked = TRUE) then PrintMode = "C"
if (LongPF->checked = TRUE) then PrintMode = "L"
!report PrintDD {
...
FieldNo = 1
while (FieldNo <= tmp.NumFields) {
PrintFuncName = "PrintField" / PrintMode
PrintFuncPtr = &fromname(PrintFuncName)
PrintFuncPtr()
FieldNo ++
}
}
!function PrintFieldN() {
statements
}
!function PrintFieldC() {
statements
}
!function PrintFieldL() {
statements
}
Example with a nested record array:
!record Rec1[2] {
!record SubRec[4] {
num,,i4[10]
}
}
ptr =& fromname("Rec1[2].SubRec[3].num[ Rec1[2].SubRec[5].num[1] ]")
RELATED TOPICS |