Recent

Author Topic: procedure doesn't match class declaration but still works ?  (Read 2292 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1623
Re: procedure doesn't match class declaration but still works ?
« Reply #15 on: July 05, 2023, 06:33:39 pm »
With due respect, Thaddy is a too wise 노친네. This is not an offensive expression ^^ㅡ

PascalDragon

  • Hero Member
  • *****
  • Posts: 6049
  • Compiler Developer
Re: procedure doesn't match class declaration but still works ?
« Reply #16 on: July 05, 2023, 11:12:01 pm »
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
Code: Pascal  [Select][+][-]
  1.  PUBLIC { public declarations }
  2.     PROCEDURE INIT (CONST ATABLENAME,ACOLNAME:ShortString;CONST WANT_TO_TOGGLE:BOOLEAN;
  3.                     CONST UPDATE_TYPE:BOOLEAN = FALSE);
however it seems to compile and work ok if i have this
Code: Pascal  [Select][+][-]
  1.   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.

Joanna

  • Hero Member
  • *****
  • Posts: 1380
Re: procedure doesn't match class declaration but still works ?
« Reply #17 on: July 05, 2023, 11:44:04 pm »
Quote
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.

Just another reason why I pascal is better than c++ 8)
For me looking at the procedure I really want to see that it has a default value and what that default value will be without going all the way to class declaration. I hope that someday this will enforce more consistent behavior. Then again I really don’t understand how default values work internally but still...

Zvoni

  • Hero Member
  • *****
  • Posts: 3007
Re: procedure doesn't match class declaration but still works ?
« Reply #18 on: July 06, 2023, 08:20:24 am »
For me looking at the procedure I really want to see that it has a default value and what that default value will be without going all the way to class declaration.
....Put a Comment behind the argument......
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Joanna

  • Hero Member
  • *****
  • Posts: 1380
Re: procedure doesn't match class declaration but still works ?
« Reply #19 on: July 06, 2023, 02:13:28 pm »
I just added the full declaration with default value back into the procedure implementation ... I guess I have to be more careful with future default parameter to make sure they are correct.

 

TinyPortal © 2005-2018