Using Genero records
When passing a RECORD to a Java
method, the runtime system converts the RECORD to an instance of the
com.fourjs.fgl.lang.FglRecord class implemented in
$FGLDIR/lib/fgl.jar.
The FglRecord object is a copy of the RECORD variable;
structure and members of the FglRecord object can be read within the Java code, but
cannot be modified.
You must add $FGLDIR/lib/fgl.jar to the class path in order to compile Java
code with com.fourjs.fgl.lang.FglRecord class.
The com.fourjs.fgl.lang.FglRecord class implements the following methods:
| Method | Description |
|---|---|
|
Dereferences the underlaying member variables. |
|
Returns the double value of the record member at position p. |
|
Returns the FglByteBlob value of the record member at position p. |
|
Returns the FglDate value of the record member at position p. |
|
Returns the FglDateTime value of the record member at position p. |
|
Returns the FglDecimal value of the record member at position p. |
|
Returns the FglInterval value of the record member at position p. |
|
Returns the FglTextBlob value of the record member at position p. |
|
Returns the number of record members. |
|
Returns the name of the record member at position p. |
|
Returns the int value of the record member at position p. |
|
Returns the String representation of the value of the record member at position p. |
|
Returns the FglTypes constant of the record member at position p. |
|
Returns the string representation of the data type of the record member at position p. |
|
Returns the encoded type qualifier of the record member at position p. |
com.fourjs.fgl.lang.FglRecord to
identify the members of the
RECORD:public static void showMemberTypes(FglRecord rec){
int i;
int n = rec.getFieldCount();
for (i = 1; i <= n; i++)
System.out.println( String.valueOf(i) + ":" +
rec.getFieldName(i) + " / " + rec.getTypeName(i) );
}When assigning a RECORD to a com.fourjs.fgl.lang.FglRecord,
widening conversion applies implicitly. But when assigning a
com.fourjs.fgl.lang.FglRecord to a RECORD, narrowing
conversion applies and you must explicitly CAST the original object reference to the type of the
RECORD. The following example shows how to return an FglRecord object from a Java
method:
The PassRecord.4gl source:
IMPORT JAVA com.fourjs.fgl.lang.FglRecord
IMPORT JAVA UseRecord
MAIN
TYPE type1 RECORD
id INTEGER,
name VARCHAR(50)
END RECORD
DEFINE rec1, rec2 type1
LET rec1.id = 123
LET rec1.name = "McFly"
LET rec2 = CAST(UseRecord.getRecord(rec1) AS type1)
END MAIN
import com.fourjs.fgl.lang.FglRecord;
public class UseRecord{
public static FglRecord getRecord(FglRecord rec){
...
return rec;
}
}