I have noticed a rather annoying oddity with Delphi toolbars. I have a TToolbar that has logical groups of icons. To make the grouping stand out I would like to use separator buttons, with style tbsDivider.
When I do this, it looks like this:

Note the double vertical lines between each icon. The right hand one is in the middle of the separator tool button. The left hand one is on the left edge of the separator tool button.
So, I can switch to tbsSeparator which removes the middle line:

But I’m not keen on that since I’d like the divider to be in the middle.
I looked at an ancient version of my real app and found that it had centred separators. It seems that is possible when Windows themes are disabled. Here’s what it looks like with tbsDivider and the application manifest removed:

That’s the layout I am looking for. Is this attainable when themes are active?
I did find a discussion of the issue on the Embarcadero forums, but there was no useful insight: https://forums.embarcadero.com/message.jspa?messageID=467842
For sake of completeness, here’s the pertinent extract from the .dfm file
object ToolButton1: TToolButton
Left = 0
Top = 0
ImageIndex = 0
end
object ToolButton2: TToolButton
Left = 23
Top = 0
Width = 16
ImageIndex = 1
Style = tbsDivider
end
object ToolButton3: TToolButton
Left = 39
Top = 0
ImageIndex = 1
end
object ToolButton4: TToolButton
Left = 62
Top = 0
Width = 16
ImageIndex = 2
Style = tbsDivider
end
object ToolButton5: TToolButton
Left = 78
Top = 0
ImageIndex = 2
end
The native control draws the vertical line for a separator button when the toolbar has the flat style. So if you remove the flat style, you’d be left alone with the VCL’s divider line. You can safely remove the style when the application is themed, themed toolbar buttons does not regard flat style (why toolbar separators does, I have no idea). However when themes are disabled there’ll again be two lines. In that case keeping separators instead of dividers seems like the better option.
One would guess unsetting the
Flatproperty would have any effect as the documentation states. HoweverTToolBar.CreateParamsunconditionally enables it whenStyleServicesis enabled. So an API call is necessary;This eliminates part of the problem, the remaining part is the divider line is not exactly in the center between two buttons. VCL’s problem here is, it does not want to draw the line itself. So it calls the theme api which draws the separator line to the left of the separator. To circumvent, VCL passes about the right half of the separator rectangle to the api, and the line gets about in the middle. I don’t know if there’s any way to tell exactly where the theme api draws it and I doubt there is.