#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    55
    Rep Power
    10

    TMenuItem - find a item in all TMenuItem


    I have a TMenuItem, and I want to know if the TMenuItem already have a MenuItem.
    My TMenuItem have n levels
    I try that using some like this:
    Code:
    subItem := Menu.Items.Find('xpto')
    if subItem = nill then
    begin
    showmessage('Item do not exists');
    end;
    But this code only search in the first level.
    Is the TMenuItem have one function that search a item in the all TMenuItem?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Posts
    51
    Rep Power
    9
    Originally Posted by astro__pc
    I have a TMenuItem, and I want to know if the TMenuItem already have a MenuItem.
    My TMenuItem have n levels
    I try that using some like this:
    Code:
    subItem := Menu.Items.Find('xpto')
    if subItem = nill then
    begin
    showmessage('Item do not exists');
    end;
    But this code only search in the first level.
    Is the TMenuItem have one function that search a item in the all TMenuItem?

    you need to check for the existence of submenu items yourself. I suggest you use a recursive procedure to enumerate your menu tree.

    -Michael
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    55
    Rep Power
    10
    I left here the solution that I make.
    It is a recursive function.
    That search in TMenuItem a TMenuItem with one specific caption.

    Code:
    function TFPrincipal.ProcuraItem(menuG: TMenuItem; str: String): TMenuItem;
    var
      j: Integer;
      item,itemAux: TMenuItem;
      teste: String;
    begin
      j:=0;
    
      //first level
      item:= menuG.Find(str);
      if item <> nil then
      begin
          //ShowMessage('find in the first level');
          Result:= item;
          Exit;
      end;
    
      //sub-levels
      while j < menuG.Count do
      begin
    
        teste := menuG.Items[j].Caption;
    
        item:= menuG.Items[j].Find(str);
        if item <> nil then
        begin
          //ShowMessage('find in the midle');
          //ShowMessage(item.Caption);
          Result:= item;
          Exit;
        end;
    
        itemAux :=  ProcuraItem(menuG.Items[j],str);
        //ShowMessage(item.Caption);
        if itemAux <> nil then
        begin
            Result := itemAux;
            Exit;
        end;
        Inc(j);
      end;
    
      //if not found, return nil
      Result:= nil;
    end;
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by astro__pc
    I left here the solution that I make.
    It is a recursive function.
    That search in TMenuItem a TMenuItem with one specific caption.

    Code:
    function TFPrincipal.ProcuraItem(menuG: TMenuItem; str: String): TMenuItem;
    var
      j: Integer;
      item,itemAux: TMenuItem;
      teste: String;
    begin
      j:=0;
    
      //first level
      item:= menuG.Find(str);
      if item <> nil then
      begin
          //ShowMessage('find in the first level');
          Result:= item;
          Exit;
      end;
    
      //sub-levels
      while j < menuG.Count do
      begin
    
        teste := menuG.Items[j].Caption;
    
        item:= menuG.Items[j].Find(str);
        if item <> nil then
        begin
          //ShowMessage('find in the midle');
          //ShowMessage(item.Caption);
          Result:= item;
          Exit;
        end;
    
        itemAux :=  ProcuraItem(menuG.Items[j],str);
        //ShowMessage(item.Caption);
        if itemAux <> nil then
        begin
            Result := itemAux;
            Exit;
        end;
        Inc(j);
      end;
    
      //if not found, return nil
      Result:= nil;
    end;
    this code helps me... thank you...
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0
    astro__pc, how i contact you?

IMN logo majestic logo threadwatch logo seochat tools logo