The Road to Delphi

Delphi – Free Pascal – Oxygene

Adding VCL Styles support to a TPopupMenu in 2 lines of code.



This is an old article if you are looking how add vcl styles support to the Menus, dialogs and more try the VCL Styles Utils  project.

The TPopupMenu component has not support for Vcl Styles directly, so if you use this control in a form with Vcl Styles enabled you will get a result like this.

To fix this you have 2 ways :

  1. Write a style hook for a TPopUpMenu (The hard way)
  2. Or use the TPopupActionBar component (the easy way)

In this post I will show you how use the option 2, taking advantage of two facts

  1. The TPopupActionBar component has full support for Vcl Styles
  2. Descends directly from the TPopupMenu component.

So adding the Vcl.ActnPopup unit to your project and using a interposer class (before of the form declaration which contains the PopupMenu), you can add vcl styles to the TPopupMenu component.

uses Vcl.ActnPopup;
type TPopupMenu=class(Vcl.ActnPopup.TPopupActionBar);

This is the result after of add the 2 above lines of code.

Author: Rodrigo

Just another Delphi guy.

25 thoughts on “Adding VCL Styles support to a TPopupMenu in 2 lines of code.

  1. Thanks a lot Rodrigo, very helpful well done

  2. Good tip, would it be simpler though to just change the declaration of the TPopupMenu to TPopupActionBar in the .dfm and .pas? Then there is no need for an interposer class.

  3. Is there a QC report for that omission?

  4. Is there any way to use “something like this” to style TMainMenu?

  5. The trick with the TPopupActionBar instead of the TPopupMenu has one flaw: if one menuitem of the menu is set to default:=true, then the application crashes with a stack overflow when trying to show the menu. This only happens if you change the VCL style.
    Does this happen to anyone else than me?

  6. Hi Rodrigo. I have a doubt about using VCL Themes.
    When i use themes, it looks like some of my custom modifications gets overriten.
    An example would be the ‘Font Color’ of my DBEdits. I had set it to BLUE and when i use styles, it just goes BLACK. Is there an workaround about this?


  7. Hi
    Right To Left direction not supported in this method!!!

  8. Why “AutoHotkeys:= maManual”invalid?Thanks

  9. Thank you Rodrigo for this.
    Is there a way to make the TMenuItem Break property work too?
    Using this trick that property is just ignored.
    I guess the “Hard way” is needed for this.

  10. HI,
    I’m also interested in the MenuItem Property Break and the property Bitmap. Both will be ignored if i use the interposer class TPopupActionBar. Is there a simple way to handle this or do i have to write my own TPopupMenu StyleHook?

  11. Pingback: VCL Styles Utils and Popup Menus – Major Update | The Road to Delphi - a Blog about programming

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s