Calling Object Methods

Object methods typically perform a sequence of operations on the associated object.

All method parameters are passed by value, so a method cannot modify DataBasic variables. However, DBO variables 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({parameter-list})

Syntax elements

objectAn expression that evaluates to a language object.

methodThe method name.

parameter-listOne or more expressions, separated by commas, representing actual values to be passed into the method.

Applicability

Language objects only.

Operation

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

Getting object methods

An object's methods can be determined by using the %Admin special method with the GetMethods keyword; for example:

Methods = MyObject->%Admin(GetMethods)

Method parameter list

The execution of any object method allows for a parameter list, which is optional only in the sense that not all methods require parameters.

The parameter list can contain multiple parameters each of which can be a DataBasic variable or expression. Unlike standard DataBasic calls and external user functions, these parameters are passed by value not reference and so cannot be altered by the method. However, note that when a parameter is an object reference the called method can change the contents of that object.

Valid parameters are characters, strings (including dynamic arrays), integers, floating point numbers, booleans and DBOs. (Note that complete dimensioned arrays or vectors cannot be specified, only specific individual elements.)

Object oriented languages support what is referred to as method signatures or overloading whereby there may be two or more methods of the same name but with different parameter lists. The language server can determine which method is being called from DataBasic by matching both the method name and the number and types of the parameters provided.

Each parameter can optionally be typed at compile time by supplying a type in parentheses prior to the actual parameter; see Type Casting.

Methods that return an array

Java

For Java, this depends on the data types in the array:

Note

There is an exception for Byte arrays; they are automatically converted to strings.

.NET

Arrays returned by .NET methods are always references to an Array object. You can use the Array.Length property to discover the length of the array, and the @Element pseudo-field to access individual elements of the array.

Examples

Calls the Table.getDefaultCell() method, with no parameters, and assigns the result to the DefaultCell variable.

DefaultCell = Table->getDefaultCell()

Calls the Table.getCell() method with a parameter where parameter typing will be handled automatically

Cell = Table->getCell(CellNo)

Calls the Table.getCell() method with an explicitly typed parameter.

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

Calls the Document.open() method with no parameters.

Document->open()

Calls the Document.open() method with un-typed parameter "jpg".

Document->open("jpg")

Calls the Document.open() method with parameter "jpg" which is a string.

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