Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I visually design a component in C++ Builder?

I have been away from C++ for a couple of years now doing AS3/Flex work. I have gotten used to being able to create a component and place it in design mode with very little fuss and I am struggling to get my head around the C++ Builder way of doing the same thing.

I have written many components for C++ Builder in the past, but none of them have been visual. What I would like to do now is create a component for customer search and another for order processing because I want to be able to create a new instance of these on the fly. What I don't want to do is have to place each of the components like the dbgrid and search fields manually in code. I would like to do this (as well as set their properties) in design mode.

How do I go about this? I have browsed the source for other Delphi components and I notice they have dfm files which seems to be what I need. How do I do this in C++ Builder? The only option I see is to add a new form if I want a dfm, but this isn't what I want as my components will be based on TPanel.

Is there a way to do this or do I have to resort to doing it all in code with no visual reference?

Pursuing the DFM idea I did a test this morning where I created a component based on TPanel and added a new form to it which I create and parent in the constructor of the component. In design mode I set the form border to none and placed a grid on it. This all looks OK until I place the component in my application, at that point it looks like a panel with a standard looking form in it and the grid is missing. If I run the app the panel shows as expected, borderless and with a grid. The DFM appears to be ignored in design mode for some reason.

If you know a better way to do this than using components then please give me some pointers.

Any help and advice will be appreciated beyond words

like image 895
Gary Benade Avatar asked Feb 26 '10 08:02

Gary Benade


2 Answers

You might want to have a look at frames (look for "Frame objects"). They are "subforms" you can design visually and then place on forms.

like image 75
Uli Gerhardt Avatar answered Oct 25 '22 20:10

Uli Gerhardt


Just as an FYI item, you can also drop the panel on a form, put any other controls on it, position them, set captions, etc..

Now, click the panel to select it, and use Component->Create Component Template from the IDE's main menu. This creates a unit you can install as a component which will add the panel and it's sub-controls (as a single component) to the IDE's component palette.

Of course, you can then modify the source for that new component like any other component source.

like image 4
Ken White Avatar answered Oct 25 '22 21:10

Ken White