Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Item added to context menu is always disabled

Post Reply
felipesilva
Posts: 2
Joined: Thu Mar 06, 2025 12:31 pm

Item added to context menu is always disabled

Post by felipesilva »

In the ChromiumBeforeContextMenu event, I clear the context menu options and add new options.

Code: Select all

procedure TFraChromium.ChromiumBeforeContextMenu(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
  const params: ICefContextMenuParams; const model: ICefMenuModel);
var
  LOption: TMenuOption;
begin
  model.Clear;

  for LOption in FMenuOptions do
  begin
    case LOption.Id
      of 0: model.AddSeparator;
      else
      Begin
        model.AddItem(LOption.Id, LOption.Caption);
        model.SetEnabled(LOption.Id, True);
      End;
    end;
  end;
end;
However, even after passing through the model.SetEnabled method, it remains disabled.

What can I do to resolve the situation?

I am using version 131 of CEF4Delphi.
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Item added to context menu is always disabled

Post by salvadordf »

Hi,

Please check the new menu IDs. All user-defined menu IDs should come between MENU_ID_USER_FIRST and MENU_ID_USER_LAST to avoid overlapping the Chromium and CEF ID ranges.

See the MiniBrowser demo.
https://github.com/salvadordf/CEF4Delphi/blob/0206d90fb01f16508e348d8bfbb1111c8a9ecdce/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L44
https://github.com/salvadordf/CEF4Delphi/blob/0206d90fb01f16508e348d8bfbb1111c8a9ecdce/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L402
felipesilva
Posts: 2
Joined: Thu Mar 06, 2025 12:31 pm

Re: Item added to context menu is always disabled

Post by felipesilva »

That was exactly it.

I looked at the example and adapted my code as mentioned in the example, and it worked.

Thank you very much!
Post Reply