views:

216

answers:

2

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

+4  A: 

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.

Ulrich Gerhardt
perfect! thank you :)
Gary Benade
+3  A: 

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.

Ken White
Does this really create a unit?
Ulrich Gerhardt
good to know, I'll give it a try, thanks Ken
Gary Benade
@Ulrich: Yep. It actually creates a compound component you can install to the component palette.
Ken White
@Ken: Could you tell me where I can find this unit? I couldn't find where my component templates are stored at all (under D2007 if that matters).
Ulrich Gerhardt
@Ulrich: Hmmm... I don't know. I always assumed it created a source unit somewhere and just added to one of the default packages, but it doesn't appear to do so (in D2010, anyway). It just sort of magically appears in the Component Palette, and when you drop it on a new form it adds the individual controls (with correct parentage) to the implementation section of the form.I'll have to dig into this one a little bit. :-)
Ken White
Found it: %AppData%\Borland\BDS\5.0\bds.dct. Unfortunately binary.
Ulrich Gerhardt
You got there before I could. Thanks for the update. It appears this method wouldn't be a full replacement for the functionality of frames, but I'll leave the post as something maybe useful for people who don't know that Component Templates exists.
Ken White