|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
Quote:
you need to check for the existence of submenu items yourself. I suggest you use a recursive procedure to enumerate your menu tree. -Michael |
|
#3
|
|||
|
|||
|
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;
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > TMenuItem - find a item in all TMenuItem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|