1
votes

how can I get caption of an item or a category when mouse is entering on them? how can I get the current caption of an item or a category when right clicking on them? I assigned a popup menu to categorybuttons. Now I need to obtain the current item or category captions and save them in variable. Because my popup menu has an item that by clicking on it it opens a new form so I want to use this variables values here.

Something like this works at click event :

Current_Items, Current_Category: String

procedure TForm1.CategoryButtons1Click(Sender: TObject);
begin
  Current_Items := CategoryButtons1.CurrentCategory.Items
    [CategoryButtons1.SelectedItem.Index].Caption;
  Current_Category := CategoryButtons1.CurrentCategory.Caption;
end;

But I need to obtain them when right click. Can someone helps me to do this? Thank you...

1
To get the component that has triggered a popup menu to popup you can get by the PopupComponent property of the popup menu. And you can still pass those information as parameters to another form. I mean, in the popup menu item action event you can open your form passing the button information to the form whilst getting the current action source by PopupComponent.Victoria
@Victoria I think your suggestion will not work, because the categories and buttons are not separately identifiable on the popup level. The popupcomponent will be the whole CategoryButtons1Tom Brunberg
@Tom, I'm not sure about it (cannot test), but you should get the component that has triggered the popup menu to popup this way (no matter how it's arranged by a container). Of course such button must be enabled, otherwise you'd need to inspect which control is under the cursor. I'm not a friend of storing variables like that btw. I would create a method in that form and pass it as parameters.Victoria
@Victoria I repeat: the component that triggers the popup is the CategoryButtons1 component. There are no published properties for the categories or the individual buttons, to which a popup could be attached.Tom Brunberg
@Tom, ok, I see, you are right. The TCategoryButtons component is a special container with no real subcomponents.Victoria

1 Answers

0
votes

Edit:

Use the OnHotButton event to prepare the Current_Item variable. That gives you the Item on which the mouse right button is clicked, but not the category.

Just note however that this does not select (activate) that particular button.

var
  Current_Items, Current_Category: String;

procedure TForm17.CategoryButtons1HotButton(Sender: TObject;
  const Button: TButtonItem);
begin
  if Button <> nil then
    Current_Items := Button.Caption;
end;

Then use Current_Items to identify which button is hot when you popup the menu.