How Front End Extensions work

This small tutorial on how to create your own extension explains the mechanism of Front End Extensions.

STEP 1: The 4GL code

Front end extensions can be called using the ui.Interface.frontCall()built-in function. See the Runtime System documentation for more information about this function.
CALL ui.Interface.frontCall(
  module, function, <in-list>, <out-list>)

For example, if the extension is called myExt, the function used is makeSum, and the function takes 2 parameters in and returns an integer and a string:

MAIN

DEFINE a,b INTEGER -- the two IN parameters
DEFINE c INTEGER -- the integer returned
DEFINE res STRING -- the string returned

LET a=1
LET b=3
CALL ui.Interface.frontCall( "myExt", "makeSum", [a,b], [c,res])
DISPLAY res
DISPLAY c

END MAIN

STEP 2: Internal GDC mechanism - the stack

To transmit parameters to the extension, GDC uses a stack; a and b will then be pushed on that stack.

STEP 3: Call the external function

All the information needed by the front end is transmitted to the extension using a front end interface structure. This structure contains a list of function pointers to:
  • manage the stack (push or pop for each handled data type)
  • get information on the function (number of IN or OUT parameters)
  • get information about the front end
For this reason the prototype of each function should be the same.

STEP 4: The extension function is running

The classic process is:
  1. Check that the number of parameters is correct
  2. Retrieve the parameters using the stack functions
  3. Do what the function has to do
  4. Use the stack functions to stack the return values
  5. Return 0 in case of success

STEP 5: Internal GDC mechanism - the stack

The GDC uses the stack to un-stack the returned values and transmit them to the Runtime System, which dispatches the values into the right variable.