Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7728405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:42:31+00:00 2026-06-01T05:42:31+00:00

Please consider such scenerio: I have component called TMenuItemSelector which has two published properties:

  • 0

Please consider such scenerio:

I have component called TMenuItemSelector which has two published properties: PopupMenu – allows to pick an instance of TPopupMenu from the form and MenuItem which allows to pick any instance of TMenuItem from the form.

I would like to modify property editor for MenuItem property in a way that when PopupMenu is assigned then only menu items from this PopupMenu are visible in a drop down list.

I know that I need to write my own descendant of TComponentProperty and override GetValues method. The problem is that I do not know how to access the form on which TMenuItemSelector is lying.

Original TComponentProperty is using this method to iterate all available instances:

procedure TComponentProperty.GetValues(Proc: TGetStrProc);
begin
  Designer.GetComponentNames(GetTypeData(GetPropType), Proc);
end;

However, Designer seems to be precompiled so I have no idea how GetComponentNames works.

This is what I have so far, I guess only thing which I am missing is the implementation of GetValues:

unit uMenuItemSelector;

interface

uses
  Classes, Menus, DesignIntf, DesignEditors;

type
  TMenuItemSelector = class(TComponent)
  private
    FPopupMenu: TPopUpMenu;
    FMenuItem: TMenuItem;
    procedure SetPopupMenu(const Value: TPopUpMenu);
    procedure SetMenuItem(const Value: TMenuItem);
  published
    property PopupMenu: TPopUpMenu read FPopupMenu write SetPopupMenu;
    property MenuItem: TMenuItem read FMenuItem write SetMenuItem;
  end;

type
  TMenuItemProp = class(TComponentProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure GetValues(Proc: TGetStrProc); override;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterPropertyEditor(TypeInfo(TMenuItem), TMenuItemSelector, 'MenuItem', TMenuItemProp);
  RegisterComponents('Test', [TMenuItemSelector]);
end;

{ TMenuItemSelector }

procedure TMenuItemSelector.SetMenuItem(const Value: TMenuItem);
begin
  FMenuItem := Value;
end;

procedure TMenuItemSelector.SetPopupMenu(const Value: TPopUpMenu);
begin
  FPopupMenu := Value;
end;

{ TMenuItemProperty }

function TMenuItemProp.GetAttributes: TPropertyAttributes;
begin
  Result := inherited GetAttributes + [paValueList, paSortList];
end;

procedure TMenuItemProp.GetValues(Proc: TGetStrProc);
begin
  //How to filter MenuItems from the form in a way that only
  //MenuItems which belong to TMenuItemSelector.PopupMenu are displayed? \
  //And how to get to that form?
  //inherited;

end;

end.

Anyone could help?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:42:33+00:00Added an answer on June 1, 2026 at 5:42 am

    When TMenuItemProp.GetValues() is called, you need to look at the TMenuItemSelector object whose MenuItem property is currently being edited, see if that object has a PopupMenu assigned, and if so then loop through its items as neded, eg:

    procedure TMenuItemProp.GetValues(Proc: TGetStrProc); 
    var
      Selector: TMenuItemSelector;
      I: Integer;
    begin 
      Selector := GetComponent(0) as TMenuItemSelector;
      if Selector.PopupMenu <> nil then
      begin
        with Selector.PopupMenu.Items do
        begin
          for I := 0 to Count-1 do
            Proc(Designer.GetComponentName(Items[I]));
        end;
      end else
        inherited GetValues(Proc);
    end; 
    

    BTW, you need to implement TMenuItemSelector and TMenuItemProp in separate packages. With the exception of the RegisterComponents() function, (which is implemented in a runtime package), design-time code is not allowed to be compiled into run-time executables. It is against the EULA, and Embarcadero’s design-time pacakges are not allowed to be distributed. You need to implement TMenuItemSelector in a runtime-only package, and then implement TMenuItemProp and Register() in a designtime-only package that Requires the runtime-only package and uses the unit that TMenuItemSelector is declared in, eg:

    unit uMenuItemSelector;
    
    interface
    
    uses
      Classes, Menus;
    
    type
      TMenuItemSelector = class(TComponent)
      private
        FPopupMenu: TPopUpMenu;
        FMenuItem: TMenuItem;
        procedure SetPopupMenu(const Value: TPopUpMenu);
        procedure SetMenuItem(const Value: TMenuItem);
      protected
        procedure Notification(AComponent: TComponent; Operation: TOperation); override;
      published
        property PopupMenu: TPopUpMenu read FPopupMenu write SetPopupMenu;
        property MenuItem: TMenuItem read FMenuItem write SetMenuItem;
      end;
    
    implementation
    
    { TMenuItemSelector }
    
    procedure TMenuItemSelector.Notification(AComponent: TComponent; Operation: TOperation);
    begin
      inherited;
      if Operation = opRemove then
      begin
        if AComponent = FPopupMenu then
        begin
          FPopupMenu := nil;
          FMenuItem := nil;
        end
        else if AComponent = FMenuItem then
        begin
          FMenuItem := nil;
        end;
      end;
    end;
    
    procedure TMenuItemSelector.SetMenuItem(const Value: TMenuItem);
    begin
      if FMenuItem <> Value then
      begin
        if FMenuItem <> nil then FMenuItem.RemoveFreeNotification(Self);
        FMenuItem := Value;
        if FMenuItem <> nil then FMenuItem.FreeNotification(Self);
      end;
    end;
    
    procedure TMenuItemSelector.SetPopupMenu(const Value: TPopUpMenu);
    begin
      if FPopupMenu <> Value then
      begin
        if FPopupMenu <> nil then FPopupMenu.RemoveFreeNotification(Self);
        FPopupMenu := Value;
        if FPopupMenu <> nil then FPopupMenu.FreeNotification(Self);
        SetMenuItem(nil);
      end;
    end;
    
    end.
    

    .

    unit uMenuItemSelectorEditor;
    
    interface
    
    uses
      Classes, DesignIntf, DesignEditors;
    
    type
      TMenuItemSelectorMenuItemProp = class(TComponentProperty)
      public
        function GetAttributes: TPropertyAttributes; override;
        procedure GetValues(Proc: TGetStrProc); override;
      end;       
    
    procedure Register;
    
    implementation
    
    uses
      Menus, uMenuItemSelector;
    
    procedure Register;
    begin
      RegisterComponents('Test', [TMenuItemSelector]);
      RegisterPropertyEditor(TypeInfo(TMenuItem), TMenuItemSelector, 'MenuItem', TMenuItemSelectorMenuItemProp);
    end;
    
    { TMenuItemSelectorMenuItemProp }
    
    function TMenuItemSelectorMenuItemProp.GetAttributes: TPropertyAttributes;
    begin
      Result := inherited GetAttributes + [paValueList, paSortList] - [paMultiSelect];
    end;
    
    procedure TMenuItemSelectorMenuItemProp.GetValues(Proc: TGetStrProc);
    var
      Selector: TMenuItemSelector;
      I: Integer;
    begin
      Selector := GetComponent(0) as TMenuItemSelector;
      if Selector.PopupMenu <> nil then
      begin
        with Selector.PopupMenu.Items do
        begin
          for I := 0 to Count-1 do
            Proc(Designer.GetComponentName(Items[I]));
        end;
      end else
        inherited GetValues(Proc);
    end; 
    
    end.   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Remark: please consider XPath syntax dead here, thank you. I have xml node (HTML
I have an app that's about presenting fictional simplified cities. Please consider the following
Please consider the following Amount value type property which is marked as a nullable
i have trouble with building some projects. please consider this scenario: i have 2
Here's a scenario: I have a java front end (RCP/SWT) app which currently has
Please consider this example class: [Serializable] public class SomeClass { private DateTime _SomeDateTime; public
Please consider the following: <td style=width: 500px;> <div style=width: 400px;>SomeContent</div> </td> For some reason,
Please consider the following fork() / SIGCHLD pseudo-code. // main program excerpt for (;;)
Please consider the following scenario: map(T,S*) & GetMap(); //Forward decleration map(T, S*) T2pS =
Please consider this code: template<typename T> char (&f(T[1]))[1]; template<typename T> char (&f(...))[2]; int main()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.