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!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

madshi, is right (not tested yet).

you can individualize each created button by giving a unique name (property) or a number in the tag (property)

then you can decide with
   (by Name)

  If (Sender is TButton) then
    If TButton(Sender).Name = ANameVar then

  (by tag)

  If (Sender is TButton) then
    If TButton(Sender).Tag = AIntegerVar then

or if you take the fieldnames as name
(here are some restrictions)

  If (Sender is TButton) then
    Table1.FieldByName(TButton(Sender).Name).AsString := Somewhat

what should happen if a button is pressed?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I think you want user to be able to rearrange the program vision... If so, you can use TActionList instead...
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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)...
mcdonluAuthor Commented:
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?
mcdonluAuthor Commented:
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.
mcdonluAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.