adi_2010
adi_2010

Reputation: 37

Find parent of the submenu items in delphi

I want to find out parent when i click on the submenu item. For example in the image below when i click on L3B the result should be "L1/L2/L3B".

Popup menu

Upvotes: 0

Views: 1185

Answers (1)

Filipe Martins
Filipe Martins

Reputation: 608

You can use a recursive function to get the full path of your menu.

function Form1.GetMenuPath(Menu: TMenuItem): String;
begin
  if (Menu.Parent <> nil) and (Menu.Parent.ClassType = TMenuItem) then
    Result := GetMenuPath(TMenuItem(Menu.Parent));
  if Result <> '' then
    Result := Result + ' > ';
  Result := Result + Menu.Caption;
end;

At your MenuItemClick you call the function

procedure Form1.L3B1Click(Sender: TObject);
begin
  ShowMessage(GetMenuPath(TMenuItem(Sender)));
end;

Upvotes: 4

Related Questions