I have a unit that has a class that is a descendant of button and in the class i declare a procedure with a default parameter like this
PUBLIC { public declarations }
PROCEDURE INIT (CONST ATABLENAME,ACOLNAME:ShortString;CONST WANT_TO_TOGGLE:BOOLEAN;
CONST UPDATE_TYPE:BOOLEAN = FALSE);
however it seems to compile and work ok if i have this
PROCEDURE TUPDATE_BOOL_COL_BTN.INIT( CONST ATABLENAME, ACOLNAME: SHORTSTRING;CONST WANT_TO_TOGGLE: BOOLEAN; CONST UPDATE_TYPE:BOOLEAN{ = FALSE}) ;
the value seems to be correct default value of false. i am wondering why it tolerates this inconsistent procedure declaration though. is this intentional? wouldn't it be better to have compiler catch this error?
The compiler allows you to drop the default value from the definition of the routine, because what is important is the
declaration. Having to repeat the default value will just end up annoying if one needs to change the value. Other languages like C++ even outright
forbid to repeat the default value in the definition.
No, Joanna, with due respect,"constructors must be called init", depending on mode.
If that is new code, I really wonder what you are doing....
( don't call a procedure init , unless you know what you are doing and know the modes.)
As
egsuh wrote, you're missing the point. This is not about any constructor (
Joanna's code clearly shows
PROCEDURE, not
CONSTRUCTOR), not about TP-style objects (TP code wouldn't support default parameters anyway, because those were only introduced in Delphi 4) and not about the name
Init.