Optional Parameter to Procedure

Cringer

ProgressTalk.com Moderator
Staff member
I'm guessing he wants to have a parameter that you don't have to supply, but you can do. My thoughts would be that he's found an instance where he wants to change the signature of a procedure for a very small subset of calls to that procedure and doesn't want to go through changing the calls everywhere.

AFAIK this is not possible.
 

Boomn4x4

New Member
I have written a library function (C++) to be used in Progress. I am declaring the function as follows:

PROCEDURE msgi_send_one EXTERNAL {&libmsgi} CDECL PERSISTENT :
define input parameter destType as character. /* 'QUEUE' or 'TOPIC'*/
define input parameter destination as character. /* name of queue or topic */
define input parameter messageString as character. /* message byte buffer (UTF-8) string */
define input parameter messageLength as long. /* Length of message in bytes */
define return parameter returnStatus as long. /* Integer with status info. 0 = success */
END PROCEDURE.

There is one more logical paramter that I want to use, that parameter would be optionally supplied. If the parameter is not supplied, a default value of "false" would be assumed and passed to the library. "true" or "false" could also be passed.
 

Cringer

ProgressTalk.com Moderator
Staff member
The only way I can think of doing that is to have 2 procedures. The one that doesn't have the optional parameter calls the one that does with "false" presumed.

Code:
PROCEDURE ExtraParam:
  DEFINE INPUT PARAM lv-i AS INT NO-UNDO.
  DEFINE INPUT PARAM lv-lg as LOG NO-UNDO.

<code here>

END PROCEDURE.

PROCEDURE OneParam:
  DEFINE INPUT PARAM lv-i AS INT NO-UNDO.

  RUN ExtraParam (INPUT lv-i,INPUT FALSE).

END PROCEDURE.

Obviously you'd need to adapt this for C++
 

rzr

Member
if there is going to be default value (FALSE)... then why not pass a parameter always ?
 

Boomn4x4

New Member
if there is going to be default value (FALSE)... then why not pass a parameter always ?

It will be a rare occurance that TRUE would be needed, so if I could leave the parm optional, it could save having to supply the parameter, only supplying it in the rare instances its needed. Other languages support this, I was hoping OpenEdge did as well.

But, it doesn't appear that is possible, so always supplying the parameter is going to be necessary.
 

rzr

Member
How many program's will call the procedure msgi_send_one ?

you could set THIS-PROCEDURE:pRIAVTE-DATA = 'FALSE' or 'TRUE' in the calling program and check for the
SOURCE-PROCEDURE:pRIAVTE-DATA value in called program but i'd always prefer passing parameter values.......
 

Stefan

Well-Known Member
How many program's will call the procedure msgi_send_one ?

you could set THIS-PROCEDURE:pRIAVTE-DATA = 'FALSE' or 'TRUE' in the calling program and check for the
SOURCE-PROCEDURE:pRIAVTE-DATA value in called program but i'd always prefer passing parameter values.......

Although you can, you definitely should not.
 

tamhas

ProgressTalk.com Sponsor
While you might be able to kludge something, resist the urge... Consistent interfaces are a basic design principle. At most you should define a facade object without the extra parameter and have it call the real object with the parameter, the facade supplying the default value ... But think long and hard whether that is going to add confusion because you will be calling two different routines for the same purpose depending on context. Note, another technique for variable numbers of parameters is to pack the parameters into a value object or name/value string or some such so that you are only ever passing one parameter, but encoding it before the call and decoding it after ... But I wouldn't do that for a case like this.
 
Top