I'm having difficulty getting Delphi 2006 to assign event handlers to a component on a TFrame that are independent.
Say I have a frame TComboFrame
that contains a TCombo Combo1
and I use this in several places on my main form.
When I place an instance of TComboFrame MyFrame1
onto my main form, and I want to assign an
event handler to the combo, I do it by clicking on the TCombo inside
the frame MyFrame1
that I have placed on the form, and double clicking in the empty
OnChange
field in the object inspector Events tab.
Normally the creates a new handler with a name like:
procedure TMainForm.MyFrame1Combo1Change(Sender: TObject);
and the event handler name is derived from both the name of the component on the ancestor TComboFrame (Combo1
) and the name of the instance I have placed on my form (MyFrame1
) - i.e. unique to that instance of the TComboFrame. I can then
do this for other instances of the frame that I have placed on my main
form and they each get their own event handlers.
If I wanted an event handler that fired for all instances of the frame, I would open the ancestor frame itself and do it there.
This is my understanding of how it is supposed to work, but something has gone wrong somewhere. Of the several instances of the frame on my main form, some have their own event handlers, and some have a common event handler,
procedure TDMainForm.ComboFrame1Combo1Change(Sender: TObject);
Nothing I have tried has broken this phantom link Delphi seems to have with this common event handler that is shared by several of the frames.
How can I repair this state, and what causes it in the first place?
** UPDATE 1 **
I have found after reading the responses and a bit of experimenting that I can repair the offending components by the following procedure:
1) remove all event handlers for the frame.
2) delete the frame, remembering it's name.
3) copy another one that is known to be OK (i.e. has it's own event names that are "individual").
4) paste that one in place of the one you deleted.
5) Restore the original name.
6) Create your event handlers.
...at least, it worked for me at least once...
** UPDATE 2 **
Another way to cure it seems to be to overtype the event handler name that it creates when you double-click in the empty event field in Object Inspector, with a new unique name, and then double-click on the name again. Delphi then creates an empty handler with the unique name.