• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

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!
0
mcdonlu
Asked:
mcdonlu
1 Solution
 
MadshiCommented:
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.
0
 
kretzschmarCommented:
yup,

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?

meikl
0
 
denizcanCommented:
I think you want user to be able to rearrange the program vision... If so, you can use TActionList instead...
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
MadshiCommented:
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)...
0
 
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?
0
 
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.
0
 
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.
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Tackle projects and never again get stuck behind a technical roadblock.
Join Now