Link to home
Start Free TrialLog in
Avatar of mcdonlu
mcdonlu

asked on

Event handeling For dynamically created buttons

I'm working on an application which dynamically allocates buttons as needed from a database column. Here's the deal, I create the buttons dynamically, but they need to be clickalbe. Some one was already kind enough to point out how to set the Onclick property of the buttons to a procedure. However, since my procedure my create multiple buttons each time it is called, it does so itteratively. So every button has the same properties,(excepting the positioning of the buttons via a accumulating offset value). Therefore I call the same OnClick procedure everytime I click one of my newly created buttons.
Since I want this application to be as generic as possible, I want to keep a singe onclick procdure, however, I'm having troubles. Since there are multiple buttons that could use the procedure, I need a way of distinguishing wich button called it. I though it would be a simple matter of passing a TButton Parameter to it.   But the Onclick property of the buttons is of TNotifyEvent. And it won't let me(or at least I can't figure out how!) to pass additional paramaters, it only seems to work with (Sender: TObject). I thought maybe I'd have to derive my own handeler, I really have no Idea. Any help would be greatly appriciated as i'm new to delphi and struggling!

Thank you in Advance!
Avatar of Madshi
Madshi

The Sender object should be (at least I hope so) the button that was pressed. So you can ask this: "if (Sender as TButton) = Button1 then ..."

Does this help?

Regards, Madshi.
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think you want user to be able to rearrange the program vision... If so, you can use TActionList instead...
Hi denizcan,

welcome on EE...   :-)

May I ask you something friendly? Hmmm... It would be nice, if you would read the comments before locking a question with an answer. I mean, here in the Delphi forum we experts are often only posting comments to give the questioner the possibility to decide which comment is the best one. Thank you!!   (-:

Regards, Madshi.

P.S: In most other forums you better post an answer as soon as you can, because there most experts are not from the polite sort (like they are here in the Delphi forum)...
Avatar of mcdonlu

ASKER

I'm so sorry it is taking me so long to close the question...however, I can't seem to award the points to previous answers. It will only, so far as I can see, let me award to the most recent answer. And I wish to give them to an early answer. Am I missing something?
Avatar of mcdonlu

ASKER

I see. Never mind now. I see what Madshi's previous comment was all about. Thank you very much madshi, I can now award the pionts.
Avatar of mcdonlu

ASKER

Thank you very much. I can take it from here. I was unaware of the As call!
And as for the tag...that is extremely useful, I just simply didn't think of it.