2.17 :get()
With this method, the attributes of objects can be queried. This method is predefined for all objects, Models and Defaults.
Furthermore, it is possible to overwrite this method and thus to extend the way the attributes are queried by further actions (e.g. calculating attribute values only when they are actually needed).
You can find the attributes available for the relevant object type in the “Object Reference”.
Definition
anyvalue :get
(
attribute Attribute input
{ , anyvalue Index input }
)
Parameters
- attribute Attribute input
- This parameter contains the attribute whose value is queried.
- anyvalue Index input
- In this optional parameter the index of the queried attribute is specified, if it is an indexed attribute. Its data type must correspond to the index data type of the attribute. Therefore, an integer value must be passed here if the attribute is one-dimensional or an index value if the attribute is two-dimensional.
Return value
Value of the queried attribute using return.
Passing fail in overwritten, predefined methods is also possible. To do so, there are the following keywords in the Rule Language:
Syntax
pass <expression> ;
Evaluates an expression similar to a return statement in order to return the result to the caller. If an error occurs, this error status is passed on to the caller. A normal return statement would terminate here and continue with the next statement.
Thus it virtually corresponds to the simplification of
variable anyvalue V;
if fail(V:=<expression>) then
throw;
else
return V;
endif
Syntax
throw ;
This keyword is used to signal an error to the caller and terminate the current method.
Example
dialog D
model edittext MEt {
:get() {
case Attribute
in .text:
if this.content="" then
throw;
else
return this.content;
endif
endcase
pass this:super();
}
}
on dialog start {
variable string S := "???";
print fail(MEt.text); // => true
MEt.content := "Hello";
print fail(S := MEt.text); // => false
print S; // => Hello
print fail(MEt:get(.docking)); // => true
exit();
}
Implicit Invocation
The :get() method is also invoked implicitly. Whenever an attribute (predefined or user-defined) is queried from the Rule Language or by an interface function (e.g. DM_GetValue()), the method :get() is called, which must then return the value of the attribute.
Redefinition of the :get() method is done like this:
window W {
:get(<no parameters !>)
{
...
Actions to compute the value of the queried attribute.
...
}
}
Within the method definition, the parameters Attribute and Index can be queried and set, in order to then call e.g. with this:super() the method :get() of the superclass with the accordingly changed parameters, which, however, is usually not useful.
Suppression of Recursive Calls
If within the method :get() any attribute of the same object for which the :get() method has already been called is queried, the method :get() should actually be invoked implicitly again for the same object. Since the danger of an infinite recursion is very high in this case (in many cases it would even be inevitable), such a recursive call is suppressed.
Example
window {
:get()
{
case (Attribute)
in .title:
return “<” + this.title + “>”; // no implicit call of :get()
otherwise:
return this:super();
endcase
}
}
In this example, the :get() method monitors window title queries and returns the title enclosed in <>
brackets. In the process, there is another read access to this.title. But an implicit call of the :get() method is suppressed. However, the :get() method of another object will still be invoked if the attributes of the other object are queried.
Call of the :get() Method on the Superclass
The above example also shows how to use this:super(). All attributes for which the overwritten method :get() does not feel responsible should be delegated to the superclass, so that the predefined method :get() will return the attribute value at some point.
Example
The following example illustrates the call hierarchy of the :get() method.
dialog GET
model record MRec1 {
string Str;
:get()
{
if Attribute = .Str then
return "MRec1(" + this.Str + ").";
else
return this:super();
endif
}
}
model MRec1 MRec2 {
:get()
{
if Attribute = .Str then
return this:super() + "MRec2(" + this.Str + ").";
else
return this:super();
endif
}
}
MRec2 RecInst {
:get()
{
if Attribute = .Str then
return this:super() + "RecInst(" + this.Str + ")";
else
return this:super();
endif
}
}
on dialog start {
RecInst.Str := "X";
// implicit invocation of the :get() method
print "*** Result Str: " + RecInst.Str;
// should be "MRec1(X).MRec2(X).RecInst(X)"
// explicit invocation of the :get() method
print "*** Result Str: " + RecInst:get(.Str);
// should be "MRec1(X).MRec2(X).RecInst(X)"
exit();
}
See also
Built-in function getvalue() in manual “Rule Language”
C function DM_GetValue in manual “C Interface - Functions”