I made a custom numpad with numbers on it. It’s a frame and buttons in it. I put this component onto the form. Now I don’t know how to capture the active control on the form and then send number specific to the button to this control.
Can someone help me please?
The easiest way IMO is to also store the number that is the caption of the button in the button’s Tag property. You can then use the same event handler for all buttons:
The other alternative is to read the caption in the event, but then you have to do a conversion from string to Integer, which will break if you accidentally assign a button without a numeric caption to the event handler:
Note that this way you don’t have to care about whether your component is the ActiveControl or not; you just assign the event handler to every one of your component’s buttons and nothing else, and then if the event is triggered you know that the active control is your component and which one of it’s buttons was clicked.
EDIT: Based on the comment below, there’s a little more to the question than it appears.
If you’re trying to send the number to a TEdit (your “textbox”), you have to do a couple of other things. First, don’t use TButtons or TBitBtns, as they get focus and will take the focus away from your Edit control. Use TSpeedButton instead. Set the Caption of each one you want to the number you want it to put in the TEdit.
Second, since you want to put the content in the TEdit, you don’t need to bother with the tag. Set the event handler for all the TSpeedButtons to this one (which assumes your TEdit is Edit1):
This replaces any selected text in the TEdit Edit1 with the caption of the SpeedButton, or adds it at the current caret (edit cursor) position in the TEdit.
If you’re looking to put it in any one of a number of TEdits, a slight change will handle that as well:
If this is still not what you’re looking to accomplish, please edit your original question and add more information to it, so we have a chance of helping you get your answer.