Cita:
Empezado por cesarsoftware
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 AssignMethod(Components[i], 'OnClick', ControlClick);
end;
Saludos.