Extending the calculator
Return to Introduction  Previous page  Next page
User defined function DLL
Not all VO functions can be macro-compiled and so not all functions are immediately available in the calculator.

To provide a way for the non-macro compatible functions to be used, and to allow you to include any functions of your own, the calculator can be extended by the use of a DLL. When it starts the calculator looks for a DLL called VOPPCALCUDF.DLL, and if it finds it, loads it. (The name of this DLL can be changed in VOPP Plus!)

Initialising the DLL
This User Defined Function (UDF) DLL is a normal VO DLL, but needs to contain an initialisation function called _VOPPDLLRegister(). This function does not have to include any code, it is just need for VO to load the information from the DLL:

FUNCTION _VOPPDLLRegister

Functions in the DLL
Any functions you place in the DLL are accessible by the calculator. To access non-macro compatible VO functions in the calculator you should write a wrapper function, in standard CLIPPER calling convention (i.e. not PASCAL, etc), and include it in the DLL. For example, the function NTrim() is not macro compatible. A wrapper for NTrim() might be written like this:

FUNCTION NTrim_(n)
   RETURN NTrim(n)


You can then use NTrim_() in the calculator.

Translating expressions
Text in expressions can be translated into a value prior to evaluation by supplying a function called _VOPPCalcTranslate() which returns an array of text/value pairs, e.g.:

FUNCTION _VOPPCalcTranslate()

RETURN { {"MB_OK",AsString(MB_OK)}, ;
      {"FALSE",".f."}, ;
      {"TRUE",".t."}}

For example, this will allow the use of "TRUE" in the expression, and is converted to the value .T. prior to evaluation of the expression.

Sample UDF code
An example AEF called VOPP UDF.AEF is provided in the VOPP3 directory. One of functions in this UDF is a wrapper for the CreateInstance function. Note that CreateInstance requires a Symbol value passed to it so our wrapper function has to convert the text typed into the calculator into a symbol by calling String2Synbol():

FUNCTION SCreateInstance()
   LOCAL i AS DWORD
   LOCAL aParam AS ARRAY
   
   aParam := {}
   FOR i := 1 TO PCount()
      IF i == 1
         AAdd(aParam,String2Symbol(_GETFPARAM(i)))
      ELSE
         AAdd(aParam,_GETFPARAM(i))
      ENDIF
   NEXT

   RETURN _CallClipFunc(#CreateInstance,aParam)

With this UDF function available it is possible to write the following expression:

x := SCreateInstance("Infobox",,"The caption","The message text")

This returns a value of:

{(0x001C)0x02C99464} CLASS INFOBOX



The expression above has stored an InfoBox object into the variable x. You can then make use of the object later, putting in an expression such as:

x:show()

Calculating the x:show() expression results in the InfoBox appearing:




© Piko Computing Consultants, 1998-2002