Jump to content
Sign in to follow this  
Gord P

Unable to hide submenu item in TActionMainMenuBar using code

Recommended Posts

Posted (edited)

I have a separator which is the third sub item of the fourth menu item in a ActionMainMenuBar.  Because it is a separator there is no action associated with it.  

 

I have tried different routes but I am unable to access the Visible property of the item which is available in the Object Inspector at design time.

 

ActionMainMenuBar1->ActionControls[3] gets me to the fourth menu item but I am unable to drill down.

 

I tried ActionMainMenuBar1->ActionControls[3]->ActionClient->Items->Items[2] but could not access the visible property.

 

ChatGPT and CoPilot kept providing the same error proned code.

 

What is the correct way to do this?

 

(edit: I suppose I could assign an action to the separator and set the Visible property of the action to false, but there must be a proper way to access the item's Visible property without creating an action)

Edited by Gord P

Share this post


Link to post

I ended up doing what I mentioned in the edit above.  That is, created an action for the separator (changing the caption to "-") and toggled the action.  It is a simple enough solution. 

Share this post


Link to post
Posted (edited)

Now having said that, I just came across a reason why you would want to access the item instead of changing the Action itself.  For instance, if you wanted to change the caption of the menu item but you don't want the Action caption changed (say because a different control needs to have the original caption).  In this case, accessing the item itself is necessary.  This is doable at design time but I can't figure out how to do it at runtime.  Anyone have any ideas?

 

edit:  Okay I finally figured it out.  I was so close.  I needed to dynamic_cast it.  The correct line is

    dynamic_cast<TActionClientItem*>(ActionMainMenuBar1->ActionControls[3]->ActionClient->Items->Items[2])->Caption = "Finally!!!";   // or ->Visible = false;
 

Edited by Gord P
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×