Link to home
Start Free TrialLog in
Avatar of Pummel
Pummel

asked on

Making a component with other components

This question is a simplified version of what I'm actually trying to do in real life.  I will give these points to the person who helps me build the following component.  Once this is built successfully, I will know what to do to solve the real problem I have at hand.

I want to make a component called TRadioAndCombo.  It has two components: a radio button and a combo box.  When the radio button is selected, I want the combo box to be enabled.  When it is not selected, the combo box should be disabled and ItemIndex should revert back to -1.  TRadioAndCombo will also have some new properties which I will write which are independent of the child components.

At design-time, I do not want to allow the application developer to directly manipulate the radio button and combo box.  For instance, I do not want them to be able to reposition them within the TRadioAndCombo border; plus I don't want them to be able to enable and disable each component independently.

When the programmer uses TRadioAndCombo at design-time, he/she should have access to an Items property, which is merely a wrapper for the Combo's Items property.  The ItemIndex property will simply read and return the value of ItemIndex from the combo.  TRadioAndCombo.Caption should read and write to the radio button caption.  The Tag property will not read either Tag property of the radio button or combo box, but will simply be a tag for TRadioAndCombo.  Do you see where I'm going?  The new component will expose some key properties of the components that it contains, but not ALL of those properties.

As you can see, I can't inherit from TRadioButton or TComboBox because I want the functionality of both objects.  Plus, I want to hide stuff about them.  An event in TRadioButton must manipulate the ComboBox object, as described above.  I have tried using a TFrame to do all this, but that doesn't work for me since the developer has access to the two inside components.  Plus, the properties I added to the frame were not visible in the Object Inspector, even though they were published simple types.  I also seemed to have lost the radio button event handler that I wrote in the frame's unit.

When a user forward-tabs into my component, I want the radio button to have focus.  If the combo box is enabled, then another forward-tab will move the focus to the combo box.  If the user backward-tabs into my component, then focus will go to the combo box if it is enabled, and to the radio button otherwise.  TRadioAndCombo will not appear to the user as ever having focus.  The user will see the two components and just know that they work together.

I feel sure that TRadioAndCombo will have to inherit from TCustomComponent, TWinControl, or something basic like that.  Maybe it will be a TGroupBox; I don't know.  If I must design the component programmatically, then so be it, as long as it's easy for someone like me who's not quite comfortable with concepts like painting and low-level Windows messaging.  I don't think I'll have the option to design the component visually.

So, EE experts, how do I get this thing to work? :)
Avatar of kretzschmar
kretzschmar
Flag of Germany image

hi pummel(chen) :-)),

you have to write two wrapper-classes
(for the combo and the radio),
(maybe it works also with one)
which inherited from tpersistent,
where you passthrough the properties you want

as base-class, which does the both controls
bundles, you could use a twincontrol

just as kick off

meikl ;-)

Avatar of Alone
Alone

Try to inherit it from TCustomGroup box or TCustomPanel. When I've solved similar problem I've used TCustomPanel descedant
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
Avatar of Pummel

ASKER

That should do it.  Thank you.  Code always serves as a good teacher to me--more than just words and definitions.
>Code always serves as a good teacher to me
>--more than just words and definitions.

to me too :-)

thanks for points,
hope you get it work as you recommended,
if you've problems just ask in this thread,
and i will try to help you further

meikl ;-)