Recent

Author Topic: How to assign onclick event to dynamically created object ?  (Read 1692 times)

dseligo

  • Hero Member
  • *****
  • Posts: 1177
Re: How to assign onclick event to dynamically created object ?
« Reply #15 on: January 31, 2023, 06:49:51 pm »
Thanks alpine. This works:

Code: Pascal  [Select][+][-]
  1. result[i].onclick:=refText.onclick;

since refText.onclick   is refTextClick  , I still don't see why it failed doing it that way.

Because you wrote refTextClick.onclick (in your first post).

You either write method name:
Code: Pascal  [Select][+][-]
  1. result[i].OnClick := refTextClick; // or result[i].onclick := @refTextClick; for ObjFPC mode

or component and it's event:
Code: Pascal  [Select][+][-]
  1. result[i].OnClick := refText.OnClick;

lazer

  • Full Member
  • ***
  • Posts: 215
Re: How to assign onclick event to dynamically created object ?
« Reply #16 on: January 31, 2023, 07:24:24 pm »
Quote
Because you wrote refTextClick.onclick (in your first post).
Ah , indeed.  And so did the first two replies which is why that did not work either !

Anyway, as I posted in my previous reply to alpine, this is now working.  Thanks to all for replies.

dseligo

  • Hero Member
  • *****
  • Posts: 1177
Re: How to assign onclick event to dynamically created object ?
« Reply #17 on: January 31, 2023, 08:51:33 pm »
Quote
Because you wrote refTextClick.onclick (in your first post).
Ah , indeed.  And so did the first two replies which is why that did not work either !

Anyway, as I posted in my previous reply to alpine, this is now working.  Thanks to all for replies.

Yes, but since you didn't show declaration they couldn't know that your component name was refText and not refTextClick. And '@' is very often problem for people between 'mode delphi' and 'mode ObjFPC', so that is the reason for their answers.

lazer

  • Full Member
  • ***
  • Posts: 215
Re: How to assign onclick event to dynamically created object ?
« Reply #18 on: February 01, 2023, 03:55:09 am »
Quote
since you didn't show declaration they couldn't know that your component name was refText and not refTextClick.
well they couldn't know that refTextClick was not an integer variable either , but  no one assumed that. I did show the create() call of the dynamics and stated that the other variable was of the same type. There was no ambiguity.

What really caused the confusion here was the stupid error message.  Instead of complaining that refTextClick.onclick simply did not exist , it gave me some distracting BS about parameter counts.
Quote
Error: Wrong number of parameters specified for call to "refTextClick"

I was not attempting to call refTextClick,  It could have thought I was trying to call refTextClick.onclick  in that context but that does not exist. That is what the error message should have thrown out. Or it could have said refTextClick had not property called onclick.

In either case I would have realised what my mistake was instead of trying to find what the "parameter" BS was supposed to mean.

« Last Edit: February 01, 2023, 03:58:32 am by lazer »

 

TinyPortal © 2005-2018