HomeClarion Live! UniversityUsing omittable parameters
 
  • PDF

Using omittable parameters

JP (DMC): Hello Clarion world, a class question please (if anyone is around) :
I have in INC file a procedure declared like this

FillSQLQ                           PROCEDURE(BYTE pType,BYTE pOrigin,BYTE pSQL = False)

in code if I have a call declared like this :

    oDMC_Main.FillSQLQ( eDMC_Wizard , eCaseSource )

the compiler does NOT complain, would this mean having a value set in procedure declaration (the = false) is "seen" by the compiler as a default value even in a call ???

I would have thought I would need to call it with this code

    oDMC_Main.FillSQLQ( eDMC_Wizard , eCaseSource ,false or true)

Mark Sarson: Any byte value would be accepted wouldn't it? So yes default would be false.  So what your procedure is saying is that if I don't get a value for pSQL then set pSQL to false

JP (DMC): Hello Mark
Yes that I had understood, what "bothers" me is the fact the compiler does not complain when I call that procedure without anything there

it seems the compiler - because of the default value in declaration side) adds it for me : cool! avoids having to change all code calls ...

Mark.Goldberg: the prototype notation ...  

,BYTE pSQL=FALSE

is a notation for an OMITTABLE parameter that when omitted, is set to FALSE (in this case)
you could've coded it as   

,<BYTE pSQL>

and then written in the procedure

 IF OMITTED(pSQL) THEN pSQL=FALSE END

this is an example found in the LRM:

MyProc3 PROCEDURE(LONG=23)                     !Passes 23 if omitted

note: I strongly prefer seeing the label name in prototypes but of course they are not required. see LRM "Prototype Parameter Lists"

type [ label ] = default

= default
 A default value indicates the numeric parameter is omittable, and if omitted, the default value is passed. The OMITTED procedure will not detect the omission--a value is passed. Valid only on simple numeric types.

Notice the last sentence.... Valid only on simple numeric types.

JP (DMC): OH so that is why
Thanks Mark

Mark.Goldberg: it seems to me that many folks don't know all that they could about prototypes, here are some from %cwroot%\libsrc\builtins.clw

OPEN(FILE,UNSIGNED = 022H),NAME('Cla$FILE_OPEN')
ALL(STRING,UNSIGNED=255),STRING,NAME('Cla$StackALL')
HIDE(SIGNED=0,SIGNED=0),NAME('Cla$HIDE')
MESSAGE(STRING,<STRING>,<STRING>,<STRING>,UNSIGNED=0,UNSIGNED=0),UNSIGNED,PROC,NAME('Cla$MessageBox')

there are quite a few more with defult parameters in there
Joomla Template: from JoomlaShack