Recent

Author Topic: Why is it impossible to call not static object class method by object type  (Read 9001 times)

zamtmn

  • Hero Member
  • *****
  • Posts: 594
Re: Why is it impossible to call not static object class method by object type
« Reply #30 on: October 21, 2021, 10:23:38 am »
PascalDragon
Ok. thanks!

creaothceann

  • Full Member
  • ***
  • Posts: 117
Re: Why is it impossible to call not static object class method by object type
« Reply #31 on: October 25, 2021, 08:55:19 am »
[...] there is no object instance in existence that the non-static MyMethod's hidden Self parameter can refer to.
Declaring the class procedure MyMethod as static removes that hidden Self parameter from the object's class method so you can call it as if it were a classic non-method procedure, i.e. a procedure not associated with any individual object.

Why is the static keyword necessary anyway? Ideally the class keyword in front of procedure or function should already remove the hidden parameter.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Why is it impossible to call not static object class method by object type
« Reply #32 on: October 25, 2021, 09:30:10 am »
Why is the static keyword necessary anyway? Ideally the class keyword in front of procedure or function should already remove the hidden parameter.

Because for classes it makes a difference whether it's declared with static or not. For objects the correct usage - since they predate the class keyword - is procedure Name; static;. That the class keyword can be used as well is simply a remnant of classes and objects essentially sharing the same parser code.

 

TinyPortal © 2005-2018