Recent

Author Topic: Name of calling procedure?  (Read 1552 times)

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1234
Re: Name of calling procedure?
« Reply #15 on: November 04, 2024, 03:22:39 pm »
I just did an experiment and made
Ttablewhere = class(tcomponet)
As you say owner shows up but there is an access violation  crash when I try to use it like Showmessage (owner.name);

Another question is it for a class instance to create itself since nil pointers can access methods?

Like self:= tclass.create ?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

rvk

  • Hero Member
  • *****
  • Posts: 6591
Re: Name of calling procedure?
« Reply #16 on: November 04, 2024, 03:25:56 pm »
I just did an experiment and made
Ttablewhere = class(tcomponet)
As you say owner shows up but there is an access violation  crash when I try to use it like Showmessage (owner.name);
Show some more code.
You should use TWhatever.Create(owner).

Otherwise there is no owner and you can't do owner.name
If you want to do TWhatever.Create(nil) you need to check for a nil owner.
If owner <> nil then foo := owner.name.

But why do you need the owner.name?

It's better to show more code with what you want to do.
I have a feeling you are completing things a lot.

« Last Edit: November 04, 2024, 03:28:59 pm by rvk »

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1234
Re: Name of calling procedure?
« Reply #17 on: November 04, 2024, 10:56:11 pm »
Thanks everyone for the answers I decided to just redo my code.

I’m still curious about the question if class_a.procedure a calls class_b. Procedure b can I get the name of class_a from inside of class_b.procedure b?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

jamie

  • Hero Member
  • *****
  • Posts: 6735
Re: Name of calling procedure?
« Reply #18 on: November 05, 2024, 12:23:39 am »
There was a reason "Sender:Tobject" was part of method calling.
The only true wisdom is knowing you know nothing

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1234
Re: Name of calling procedure?
« Reply #19 on: November 05, 2024, 08:41:11 am »
So unless there is a sender parameter no chance of knowing what sent it?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

rvk

  • Hero Member
  • *****
  • Posts: 6591
Re: Name of calling procedure?
« Reply #20 on: November 05, 2024, 08:48:52 am »
So unless there is a sender parameter no chance of knowing what sent it?
Why do you think the whole fpc and Lazarus source is riddled with foo(Sender: TObject) procedures?

So no, not unless you go checking the call stack (which can be unreliable).

(Why don't you do things more like fpc/Lazarus does, So using TComponent with Owner and Sender in calls. Inventing your own 'convention' only complicates things and makes it harder for anyone else to understand.)

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1234
Re: Name of calling procedure?
« Reply #21 on: November 05, 2024, 10:11:34 am »
Yea I guess I was hoping to access the call stack somehow but maybe not good idea .
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

Khrys

  • Full Member
  • ***
  • Posts: 108
Re: Name of calling procedure?
« Reply #22 on: November 05, 2024, 10:39:24 am »
Yea I guess I was hoping to access the call stack somehow but maybe not good idea .

The presence of inlined functions makes this not just not a good idea, but outright impossible, unfortunately

 

TinyPortal © 2005-2018