STRING_CAST
General Form:
The STRING_CAST expression is used to declare a string expression that has a type based on a record to be a string based on a record derived from the base record. It is an error to cast a string not being declared to be of a record type. No run-time checks are performed making the operation quick, but open to misuse by the programmer.
DEFRECORD BaseRec
FLD TypeName$64
END RECORD
DEFRECORD DerivedRec EXTENDS RECORD BaseRec
FLD x
END RECORD
DIM a$_DerivedRec
FLD(a$.TypeName$)="DerivedRec"
// Can pass this BYREF to a function expecting the BaseRec
'BaseFn(BYREF a$)
DEFSUB 'BaseFn(BYREF p$_BaseRec)
// Determine from p$ that it must have been declared as a DerivedRec
IF (FLD(p$.TypeName$) == "DerivedRec")
FLD(STRING_CAST(_DerivedRec, p$).x) = 10
'DerivedFn(BYREF STRING_CAST(_DerivedRec, p$))
END IF
END SUB
GenericRecordType
It is an error to cast a string not being declared to be of a record type. If a parameter is known to contain a string of some record type it is possible to define the parameter to be of type _GenericRecordType and then use STRING_CAST when the correct type has been determined. This is demonstrated in the following example:
DEFSUB 'GenericFn(BYREF p$_GenericRecordType, typeparam)
SELECT CASE typeparam
CASE type1
'some_type1_fn(BYREF STRING_CAST(_type1, p$))
CASE type2
'some_type2_fn(BYREF STRING_CAST(_type2, p$))
END SELECT
END SUB