Ver Mensaje Individual
  #3  
Antiguo 28-01-2004
Avatar de marto
marto marto is offline
Miembro
 
Registrado: may 2003
Ubicación: Barcelona, Catalunya
Posts: 882
Reputación: 22
marto Va por buen camino
Una pequeña puntualización:

Cita:
Empezado por eduarcol
//LINEA PROPUESTA
if not(item is TMenuItem) then Exit;
//asi te aseguras de que estas trabajando con tmenusitem y no con otro componente que sea padre del menu
Lo que aquí propone educarol, funciona, aunque, bajo mi punto de vista es conceptualmente incorreto. El parametro item siempre sera del tipo TMenuItem, lo que pasa es que si nos passan una referencia a nil, no podremos contiunuar. Creo que seria más elegante (aunque igual de efectivo dejar el procedimiento así:
Código:
procedure TForm1.habilitarItems(item: TMenuItem);
begin
  if (Assigned(item.Parent) ) then
    habilitarItems (item.Parent);
  item.Visible:=true;
end;
¿Por qué cambiar HasParent por Assigned?

Cita:
Empezado por Delphi Help
ndicates that the menu item has a parent that is responsible for loading and saving its data.

function HasParent: Boolean; override;

Description

TMenuItem overrides HasParent to return True, indicating that menu items have a parent. Applications seldom call the HasParent method. It is used by the streaming system that loads and saves VCL objects to determine when another object is responsible for writing a component to a stream.
Es decir, que la función no tiene el objetivo que inicialmente pudiesemos pensar. HasParent indica quien escribirá la información de items a la RTTI, nada que ver con su Padre en el menú.
__________________
E pur si muove
Responder Con Cita