Ver Mensaje Individual
  #10  
Antiguo 15-06-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
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
Hola Cesar.

Fijate si te sirve de este modo:
Código Delphi [-]
unit Unit2;

interface

uses
  SysUtils, Classes;

procedure AssignMethod(aComponent: TComponent; const MethodName: string; aEvent: TNotifyEvent);

implementation

uses  TypInfo;

procedure AssignMethod(aComponent: TComponent; const MethodName: string; aEvent: TNotifyEvent);
var
  PInfo: PPropInfo;
  Method: TMethod;
  PEvent: ^TNotifyEvent;
begin
  PInfo:= GetPropInfo(aComponent.ClassInfo, MethodName);
  if (PInfo <> nil)and(PInfo^.PropType^.Kind = tkMethod) then
  begin
    Method:= GetMethodProp(aComponent, MethodName);
    if not Assigned(Method.Code) then
    begin
      PEvent:= @Method.Code;
      PEvent^:= aEvent;
      Method.Data:= aComponent.GetParentComponent;
      SetMethodProp(aComponent, PInfo, Method);
    end;
  end;
end;
end.

Ejemplo de uso:
Código Delphi [-]
procedure TForm1.ControlClick(Sender: TObject);
begin
  ShowMessage('Click sobre '+TComponent(Sender).Name);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  for i:= 0 to ComponentCount-1 do
    if Components[i].Name <> 'Button1' then //  para no asignarlo a Button1...
      AssignMethod(Components[i], 'OnClick', ControlClick);
end;

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita