Saturday, April 12, 2008

Alternative to TToolbar

Download sample code


If you are a DevExpress user, like me, you will use TdxBarManager instead of any of the standard Delphi controls that are available. I can imagine that CodeGear doesn't invest anything in (any of) the user interface controls with such many excellent alternatives around.

I am a VCL component developer too (for internal use that is). Most of those controls go with an ActionList for it's functions. The end user can access the functions using (amongst other things) a TToolbar. And one thing that I had not done (until today) is to replace the TToolbar component that I was using for toolbars that are part of the controls.

Now, I might be alone on this, but I think that TToolbar is one of the worst components that is in the standard package. It behaves irratically and configuring at runtime (as I do in my controls) is really a pain. Some years ago I created a subclass that kind of worked ok. But I never was happy with it.

This weekend I took it upon me to integrate the TdxBarManager into the current set of UI controls. The solution took me a bit of work, but I think that how I did might benefit others. So, I've created a demo project that demonstrates how you can use the TdxBarManager as a toolbar as part of your own UI VCL controls.

Unzip, compile the package, install it and run the demo program. That should do it.

If you have any questions, just mail me.

These examples are just a proof of concept and you will need to do some work on it to get it going. My actual code is a bit more complex than this. I might have forgotten something or made some typos.

4 comments:

stanleyxu (2nd) said...

What is your problem with the native toolbar? No chevron, no anti-aliasing rendering, some flickers, no selective text on right side, no full dropdown menu button or no Unicode support? If you are talking about these issues. I can tell you, that I have made a patch to fix all these issues.

DevExpress provides an excellent VCL control set. But once you migrate to DevExpress world, it is very difficult to go back.

Bart Roozendaal said...

Well, you named a view :-). What I found is that the order in which you add buttons is erratic. It might be my programming style, but they never turned out like I wanted.

But, I must say that I created a wrapper that made it behave like I wanted to quite some time ago, so I can't remember the exact issues with it here. I *do* remeber that I have cursed a lot while working on it. But that's all in the past now :-)

Anonymous said...

Hi Bart

Would it be possible for you to post this wrapper of yours. It looks like noone can manage to make the TToolbar do what they want.

I am having trouble resizing the buttons. The ButtonHeight property has a mind of its own!

/N.

Bart Roozendaal said...

@/N. That wrapper is long gone I'm afraid. From my memory, what I basically did was create an private list of buttons to be added and add them at the latest possible time, just before the toolbar was painted. That made sure that the order of the buttons (which was my main problem) was always correct.

I have moved to DevExpress controls quite some time ago and am using their toolbar.

Sorry, but can't help you there. If you have any specific questions though, dont't hesitate to ask them.