TMSFMXScrollMenu find a specific Item

Hello,


I have a TMSFMXScrollMenu with a certain item.
I need to add submenu to it at runtime.
I don't know how to find it.  There is an Items.FindItemID() but the ScrollItem doesn't have id property only tag property.

Thank you in advance!

Hi, 


To programmatically add an item at runtime please use the following code:
TMSFMXScrollMenu1.Items[0].AddSubItem('MyItem');

Hi Pieter ,


Thank you very much for the answer.
I think I didn't express clearly myself, it is my fault.

By "I have a TMSFMXScrollMenu with a certain item." I meant that I have a bunch lot of items and the order can change.
I cannot be sure of the position of the item (e.g. it can be Items[0] or  Items[12]). All I know is the Text or the Tag property.
So I need to find a certain item by tag (preferably) or text and then add a Subitem to it.

Thank you very much for your help!



Hi, 


Unfortunately this functionality is not included, but you can easily write your own loop:



function TForm1.FindItemByTag(ATag: Integer): TTMSFMXScrollItem;
var
  I: Integer;
  it: TTMSFMXScrollItem;
begin
  Result := nil;
  for I := 0 to TMSFMXScrollMenu1.Items.Count - 1 do
  begin
    it := TMSFMXScrollMenu1.Items[I];
    if it.Tag = ATag then
    begin
      Result := it;
      Break;
    end;
  end;
end;

Pieter Scheldeman2017-10-23 11:16:27

Thank you very much!  It works.