Ver Mensaje Individual
  #9  
Antiguo 14-06-2012
Avatar de ozsWizzard
ozsWizzard ozsWizzard is offline
Miembro
 
Registrado: may 2004
Ubicación: Murcia
Posts: 190
Reputación: 21
ozsWizzard Va por buen camino
Cita:
Empezado por cesarsoftware Ver Mensaje
Gracias ecfisa

Si que detecta el metodo, sin hacer referencia al formulario, lo que falta es que la asignacion tambien sea anonima

Código Delphi [-]
     if MethodAssigned(Components[i], 'OnExit') = False then
        TFormProveedorFactura(Components[i]).OnExit := ControlExit;

Todavia hay que hacer referencia a "TFormProveedorFactura" para asignarle el nuevo evento, ¿como podriamos hacerlo con Self o como parametro?

Thanks

Si lo que quieres es asignar ControlExit al componente, creo que te sobraría con


Código Delphi [-]
...
var
   Obj: TWinControl;
begin
     if MethodAssigned(Components[i], 'OnExit') = False then
     begin
         Obj := (Components[i] as TWinControl)
         Obj.OnExit := ControlExit;
     end;
...

Si el problema es que es el bucle el que hace:

Código Delphi [-]
     for i := 0 to TFormProveedorFactura.ComponentCount -1 do
     begin
     ...
     end;

Siempre puedes ponerle al procedimiento un "AOwner: TComopnent" y recorrer ese. Es decir:

Código Delphi [-]
unit Unit2;

interface

  function MethodAssigned(aObject: TObject; const MethodName: string): Boolean;
  
  procedure ControlEnter(Sender: TObject);
  procedure ControlExit(Sender: TObject);
  procedure ControlesResaltados(AOwner: TComponent);
  

implementation

uses  TypInfo;

function MethodAssigned(aObject: TObject; const MethodName: string): Boolean;
var
  Method: TMethod;
begin
  Method:= GetMethodProp(aObject, MethodName);
  Result:= (Method.Code <> nil)and(Method.Data <> nil);
end;

procedure ControlEnter(Sender: TObject);
begin
  TWinControl(Sender).Brush.Color := clYellow;
end;
 
procedure ControlExit(Sender: TObject);
begin
  TWinControl(Sender).Brush.Color := clWindow;
end;

procedure ControlesResaltados(AOwner: TComponent);
var
  i: word;
  Obj: TWinControl; 
begin
  for i := 0 to AOwner.ComponentCount - 1 do
  begin
    if AOwner.Components[i] is TWinControl then
    begin
      Obj := (AOwner.Components[i] as TWinControl);
      if not MethodAssigned(Obj, 'OnEnter') then       
        Obj.OnEnter := ControlEnter;
      if not MethodAssigned(Obj, 'OnExit') then
        Obj.OnExit := ControlExit;
    end;
  end;
end;
__________________
La Madurez se llama...
~~~Gaia~~~

Última edición por ozsWizzard fecha: 14-06-2012 a las 13:32:41.
Responder Con Cita