Reputation: 456
I am currently trying out the TSplitView component in Delphi 10 Seattle. The structure looks like the following:
With the second TButtonCategory I am trying to create items programmatically with the following code:
procedure TMainF.DynamicMenuButtonClick(Sender: TObject);
begin
if sender is TButtonItem then //false
ShowMessage('Sender is TButtonItem');
if sender is TCategoryButtons then //true
ShowMessage('Sender is TCategoryButtons');
end;
procedure TMainF.FormCreate(Sender: TObject);
var
i: integer;
begin
for i:=0 to 10 do begin
catMenuItems.Categories[1].Items[i] := TButtonItem.Create(catMenuItems.Categories[1].Items);
catMenuItems.Categories[1].Items[i].Caption := 'Something';
catMenuItems.Categories[1].Items[i].OnClick := DynamicMenuButtonClick;
end;
end;
In the "DynamicMenuButtonClick" procedure I want to get information about what button was clicked, the problem is that the sender which is of type TCategoryButtons doesn't tell me that. Now I was wondering if I am just missing out on something or if this is indeed just not possible.
Upvotes: 1
Views: 787
Reputation: 47704
TCategoryButtons
provides an event OnButtonClicked
which gives you the TButtonItem
. Perhaps that might be useful here.
TCatButtonEvent = procedure(Sender: TObject; const Button: TButtonItem) of object;
Upvotes: 2
Reputation: 1155
The problem is that the sender which is of type
TCategoryButtons
doesn't tell me that
Yes, it does. Use the SelectedItem
property of the TCategoryButtons
in your event handler.
procedure TForm1.DynamicMenuButtonClick(Sender: TObject);
var
categoryButtons: TCategoryButtons;
begin
categoryButtons := (Sender as TCategoryButtons);
Memo1.Lines.Add(categoryButtons.SelectedItem.Caption);
end;
Upvotes: 3