Progress
Language Reference


PROCEDURE Statement

Interfaces
OS
SpeedScript
All
All
Yes

Declares an internal procedure.

SYNTAX

PROCEDURE proc-name 
  [ EXTERNAL "dllname"
    [ CDECL | PASCAL | STDCALL ]
    [ ORDINAL n ] 
    [ PERSISTENT ]
  ]
  [ PRIVATE ]
  [ IN SUPER ] 

proc-name

The name of the internal procedure.

EXTERNAL "dllname"

Identifies the internal procedure as a Windows dynamic link library (DLL) routine or a UNIX shared library routine. The dllname argument, specified as a string literal, is the name of the DLL or library containing the routine.

CDECL

Tells Progress to use the C calling convention when accessing the routine.

PASCAL

Supported for backward compatibility only.

STDCALL

Tells Progress to use the standard Windows calling convention when accessing the routine. This is the default.

ORDINAL n

Specifies the number of the DLL entry point (the nth routine) to invoke. If you use the ORDINAL option, then proc-name can specify any name used in the corresponding RUN statement to reference the routine. If you omit the ORDINAL option, proc-name specifies which DLL routine you want to invoke.

PERSISTENT

Specifies that the DLL or shared library routine should remain loaded in memory until Progress exits or the session executes the RELEASE EXTERNAL statement.

PRIVATE

Indicates the following about the internal procedure:

IN SUPER

Indicates that the definition of the internal procedure resides in a super procedure. For more information on super procedures, see the Progress Programming Handbook .

EXAMPLES

The following example declares a Progress internal procedure that computes the factorial of an integer entered as an INPUT parameter. The result is returned as an OUTPUT parameter. Note that the procedure calls itself recursively to obtain the result.

r-factrl.p
DEFINE VARIABLE FactorialResult AS INTEGER FORMAT ">>>,>>>,>>9".
DEFINE VARIABLE FactorialInput AS INTEGER.

REPEAT:
    SET FactorialInput
             VALIDATE(FactorialInput <= 12 AND FactorialInput >= 0,
                      "Value must be between 0 and 12.").
    RUN Factorial (INPUT FactorialInput, OUTPUT FactorialResult).
    DISPLAY FactorialResult.   
END.

PROCEDURE Factorial:
   DEFINE INPUT PARAMETER  PTerm AS INTEGER.
   DEFINE OUTPUT PARAMETER FactorialResult AS INTEGER.

   DEFINE VARIABLE WorkingResult AS INTEGER.
   
   IF  PTerm <= 1 THEN DO:
      FactorialResult = 1.
      RETURN.
   END.
   ELSE DO:
      RUN Factorial (INPUT  PTerm - 1, OUTPUT WorkingResult).
      FactorialResult =  PTerm * WorkingResult.
   END.
END PROCEDURE. 

The following example declares a DLL routine, MessageBox(), which displays a message.

r-dllex1.p
DEFINE VARIABLE result AS INTEGER.

MESSAGE "  It’s a whole new world!"
  VIEW-AS 
    ALERT-BOX MESSAGE
    BUTTONS OK
    TITLE "Progress Message".

RUN MessageBoxA (0, "  It’s a whole new world, again!!",
  "Progress DLL Access", 0, OUTPUT result).

PROCEDURE MessageBoxA EXTERNAL "user32.dll":
  DEFINE INPUT PARAMETER hwnd AS LONG.
  DEFINE INPUT PARAMETER mbtext AS CHARACTER.
  DEFINE INPUT PARAMETER mbtitle AS CHARACTER.
  DEFINE INPUT PARAMETER style AS LONG.
  DEFINE RETURN PARAMETER result AS LONG.
END.  

NOTES

SEE ALSO

COM-SELF System Handle, DEFINE PARAMETER Statement, END Statement, RUN Statement, TRIGGER PROCEDURE Statement


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