DataBasic Reference > DataBasic Objects > DataBasic Server Objects Operations > Execute an Object Method

Comment on this topic

Documentation Comments

Use this form to comment on this topic. You can also provide any general observations about the Online Documentation, or request that additional information be added in a future release.

RealityV15.1Online Documentation (MoTW) Revision 7

Execute an Object Method (dbo_execute_object_method.htm)

To

Reality

Version

Topic

Submitted by

Company

Location

Email address

Comment

 

 

Execute an Object Method

Object methods typically perform a sequence of operations on the associated object. All method parameters are passed by value. Hence the method cannot modify DataBasic variables. Note however that DBOs are merely references to the actual objects on the language server which can, of course, be modified by the method.

When a method returns a result, it can be a string, number or an object, and can be used in an expression.

Syntax

Object -> method({ParameterList})

Syntax Elements

Object DBO variable name
method

The object method name that is to be executed.

-> The object operator.
ParameterList One or more expressions, separated by commas, representing actual values to be passed into the method. See 'Method Parameter List' below.

Comments

As calling a method is syntactically an expression, the method result can be used in place of a single element within a DataBasic statement.

Method Parameter List

The execution of any object methods allows for an optional parameter list.

The method parameter list can contain a variable number of parameters each of which can be a DataBasic variable or expression but, unlike standard DataBasic calls and external user functions, these parameters are passed by value not reference, and so cannot be altered by the method. The exception to this is an object which, because it is always a reference, can be modified by the method.

Valid parameters are characters, strings (including dynamic arrays), signed, unsigned or floating numbers, booleans and DBOs.

Note: Complete dimensioned arrays or vectors cannot be specified as a single parameter. Only specific individual entries can be specified.

In addition each parameter can optionally be typed at compile time by supplying a type cast in parentheses prior to the actual parameter. The type can be specified in upper or lower, but not mixed case - e.g. ({FLOAT/float – valid} {Float – invalid}).

See Variable Typing and Casting.

Examples

DefaultCell = Table->getDefaultCell()

Call method "getDefaultCell" in object "Table" with no parameters and assign the result to Variable "DefaultCell"

Cell = Table->getCell(CellNo)

Call method with a parameter where parameter typing will be handled automatically

Cell = Table->getCell( (int16) CellNo)

Call a method with an explicitly typed parameter.

Methods = Obj->getClass()->getMethods()

Get a list of methods available for an object.

Document->open()

Execute method "open" in object "Document" with no parameters.

Document->open("jpg")

Execute method "open" in object "Document" with un-typed parameter "jpg".

Document->open((string) "jpg")

Execute method "open" in object "Document" with parameter "jpg" which is a string.

Methods and Fields that Return an Array

Both method calls and fields can return an array. If the array is of primitive Java objects (numbers, strings, booleans) then an attribute mark delimited list of values will be returned.

If the array contains generic objects the Language Server creates an ArrayList (a Java language class) object and returns a reference to this. Methods of the ArrayList class can then be used to access elements of the array. For example, the special method Obj->%Admin(GetMethods) could be implemented as:

%Connect(JAVA)
%Import(java.util)
Obj = %New(String)
Methods = Obj->getClass()->getMethods(); *returns an ArrayList object
NumMethods = Methods->size();		 *size() is a method of ArrayList class
FOR I = 0 TO NumMethods – 1
CRT Methods->get(I)->toString();     *get() is a method of ArrayList class
NEXT I

Notes

RealityV15.1 (MoTW) Revision 7Comment on this topic