Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 13th, 2006, 11:52 AM
astro__pc astro__pc is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 55 astro__pc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 33 m 36 sec
Reputation Power: 4
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?

Reply With Quote
  #2  
Old February 15th, 2006, 09:13 AM
michaelm michaelm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 52 michaelm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 49 m 33 sec
Reputation Power: 3
Quote:
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

Reply With Quote
  #3  
Old February 21st, 2006, 07:34 AM
astro__pc astro__pc is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 55 astro__pc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 33 m 36 sec
Reputation Power: 4
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;

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > TMenuItem - find a item in all TMenuItem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT