13. Creating Dynamic Frames : How You Can Manipulate Data in Dynamic Fields : How You Can Access Individual Cells of a Dynamic Table Field : How You Can Create a Dynamic Expression
 
Share this page                  
How You Can Create a Dynamic Expression
You create DynExpr objects by invoking the CreateDynExpr method on an object of the Scope class. The Scope object represents the context for evaluation of the DynExpr object. The dynamic expression is no longer valid when its scope terminates, that is, when its associated application, frame, or other component, closes.
The CreateDynExpr method takes the following parameters:
string
Contains any syntactically valid OpenROAD expression except procedure or method invocations. Use the string parameter to specify the field or table field cell whose value you want to access. This parameter (which takes varchar values) can reference the field directly or can contain a valid OpenROAD expression that references the field.
The value of the string parameter is loaded into the dynamic expression created by the CreateDynExpr method. You can then use the dynamic expression to access the value of the field or cell originally specified.
For example, the following statement creates a dynamic expression (dexp) that contains the value of a cell in the Salary column of a table field named tbl:
declare
    dexp = DynExpr default null;
enddeclare
dexp = CurFrame.Scope.CreateDynExpr(string =
    'tbl[i].Salary');
When the dynamic expression is used in a GetValue, SetValue, or Assign method invocation, the value of i must be a valid row number for the array.
The value of the string parameter is evaluated within the context of the named scope. In the previous statement, the dexp dynamic expression is valid while the current frame is running. The scope in the following statement limits the dynamic expression to the current event block:
declare
    dexp = DynExpr default null;
enddeclare
dexp = CurEventScope.CreateDynExpr(string =
    'tbl[i].Salary');
Any attempt to use the dynamic expression after the event block terminates causes a runtime error.
errors
(Optional.) Provides the text of the error message. If the scope object on which the CreateDynExpr method is invoked is invalid, or the text specified in the string parameter cannot be compiled, the CreateDynExpr method returns a null.
If compilation errors occur, the CreateDynExpr method creates a string object containing the errors and sets the variable specified by the errors parameter (of StringObject data type) to point to that string object. If no compilation errors occur, this parameter is set to null.
The following statement creates a dynamic expression and sets the errors parameter:
declare
    dexp = DynExpr default null;
enddeclare
dexp = CurFrame.Scope.CreateDynExpr(string =
    'tbl[i].Salary', errors = byref(stringvar);
If an error occurs creating the dexp dynamic expression, the stringvar variable contains the error message in its Value attribute.