Progress
Language Reference


DYNAMIC-FUNCTION Function

Interfaces
OS
SpeedScript
All
All
Yes

Invokes a user-defined function. Progress evaluates the name of the function (and the procedure handle, if any) at run time.

SYNTAX

DYNAMIC-FUNCTION
  ( function-name [ IN proc-handle ] 
    [ , param1 [ , param2 ] ... ]
  ) 

function-name

A CHARACTER expression that returns the name of a user-defined function. Progress evaluates function-name at run time.

proc-handle

An expression that returns a handle to the procedure that defines the function. Progress evaluates proc-handle at run time.

param1, param2, ...

Parameters of the user-defined function. You must supply names of actual data items,-actual parameter names-not CHARACTER expressions that return parameter names.

NOTE: Progress cannot check the mode and type of the parameters at compile time, since Progress does not evaluate function-name until run time.

EXAMPLE

The following procedure demonstrates the DYNAMIC-FUNCTION function.

r-funfun.p
/* Requires a connection to the Sports database *//* define data items */DEFINE 
VAR funcs AS Char EXTENT 5 INITIAL ["firstrec",
                                           "lastrec",
                                           "nextrec",
                                           "prevrec",
                                           "quitting"] NO-UNDO.
DEFINE VAR action AS Char LABEL "Action" FORMAT "x" INITIAL "N" NO-UNDO.
DEFINE VAR idx AS Int NO-UNDO.
DEFINE VAR alldone AS Logical INITIAL No NO-UNDO.FORM WITH FRAME x SIDE-LABELS 
2 COLUMNS 1 DOWN COLUMN 25.FUNCTION dispcust RETURNS Logical:
  DISPLAY Customer  EXCEPT Comments WITH FRAME x.
END.
/* define user-defined functions */FUNCTION firstrec RETURNS Logical:
  FIND FIRST Customer.
  dispcust().
  RETURN yes.
END.
FUNCTION lastrec RETURNS Logical:
  FIND LAST Customer.
  dispcust().
  RETURN yes.
END. 
/* define more user-defined functions */
FUNCTION nextrec RETURNS Logical:
  FIND NEXT Customer NO-ERROR.
  IF AVAILABLE Customer THEN
     dispcust().
  RETURN AVAILABLE(Customer).
END. 
FUNCTION prevrec RETURNS Logical:
  FIND PREV Customer NO-ERROR.
  IF AVAILABLE Customer THEN
     dispcust().
  RETURN AVAILABLE(Customer).
END. 
FUNCTION quitting RETURNS Logical:
  alldone = yes.
  RETURN no.
END 
/* main routine */
REPEAT WHILE NOT alldone:
  UPDATE action HELP 
    "Enter F(irst), L(ast), N(ext), P(rior), or Q(uit) to navigate.".
  idx = LOOKUP(action,"f,l,n,p,q").
  IF idx EQ 0 THEN DO:
    MESSAGE "Enter F(irst), L(ast), N(ext), P(rior), or Q(uit)" 
        VIEW-AS ALERT-BOX.
    NEXT.
  END.
  DISPLAY DYNAMIC-FUNCTION(funcs[idx]) LABEL "Record Found?".
END. 

SEE ALSO

FUNCTION Statement


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095