Jump to content
IElite

TW3ListMenu selection

Recommended Posts

I am trying to determine the selection when a user clicks on the TListMenu items.

It seems that the TListMenu controls OnClick event is just the inherited TW3CustomControl event and therefore can't be used to determine the selection.

Is there a way to determine which item in the menu was selected?

 

screenshot.png

Share this post


Link to post
Share on other sites

procedure TForm1.InitializeObject;
begin
  inherited;
  {$I 'Form1:impl'}

  for var i := 0 to 4 do begin
    var item := W3ListMenu1.AddTextItem('menu ' + inttostr(i));
    item.TagValue := W3ListMenu1.Count-1;
    item.OnClick := procedure(Sender:TObject)
    begin
      writeln((sender as TW3ListMenuItemText).TagValue);
    end;
  end;
end;

Share this post


Link to post
Share on other sites

thanks @lynkfs

I guess I was hoping for a better solution - such as a OnSelection or OnSelectedItem event - as part of the ListMenu control

Having to hardcode all the menu items onclick events seems a little much

 var Item1:= fListMenu.AddTextItem('One');
 Item1.OnClick:= HandleMenuItemClick;
 var Item2:= fListMenu.AddTextItem('Two');
 Item2.OnClick:= HandleMenuItemClick;
 var Item3:= fListMenu.AddTextItem('Three');
 Item3.OnClick:= HandleMenuItemClick;
 var Item4:= fListMenu.AddTextItem('Four');
 Item4.OnClick:= HandleMenuItemClick;
 var Item5:= fListMenu.AddTextItem('Five');
 Item5.OnClick:= HandleMenuItemClick;

OR


var Item: TW3ListMenuItemText;

Item:= fListMenu.AddTextItem('One');
 Item.OnClick:= HandleMenuItemClick;
 Item:= fListMenu.AddTextItem('Two');
 Item.OnClick:= HandleMenuItemClick;
 Item:= fListMenu.AddTextItem('Three');
 Item.OnClick:= HandleMenuItemClick;
 Item:= fListMenu.AddTextItem('Four');
 Item.OnClick:= HandleMenuItemClick;
 Item:= fListMenu.AddTextItem('Five');
 Item.OnClick:= HandleMenuItemClick;

 

thanx

Share this post


Link to post
Share on other sites

Would this be what you're looking for:

  TW3ListMenuSelectedEvent = procedure(Sender: TObject; ItemIndex: Integer);

Then you'd set OnSelected once for the whole ListMenu and just add the items.

Share this post


Link to post
Share on other sites

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

×