[SOLVED] Assigning Properties and Events At Runtime
-
hello guys... I have a small component from which I got a
wrapper (.tlb)
by importing and installing the component. I dropped the component from toolbox toTMainFormDialog
and got events. But I want to redirect these events to some other class NOT theTMainFormDialog
. Now I am , well sort of, not moving forward. Well I am not sure but I think I should be able to do this using RTTI. I think I should make and assign new properties (THE events) to the old ones. This is the psuedo-code that I tried.TServer = class (TOleServer)
private
FOnEventEx : TNotifyEvent; // new one
FOnEvent : TNotifyEvent; // old onepublished
property OnEventEx : TNotifyEvent read FEventEx write FEventEx ; // new one
property OnEvent: TNotifyEvent read FEvent write FEvent; // old onepublic
procedure FireThisProc(); // This is the event I want to be fired ----------- based on new property 'OnEventEx'.
end;Now I tried the
GetMethodProc()
andSetMethodProc()
in theCreate
function of .tlb wrapper like this but could not succeed.class function CoServer : IServer
begin
MethodProp := GetMethodProp(TObject(TServer), 'OnEventEx');
SetMethodProp(TObject(TServer) , 'OnEvent', MethodProp);Result := CreateComObject(CLASS_Server) as IServer;
end;So what (and how) should I do it exactly so that I might be able to redirect my events to some other class, NOT the
TMainFormDialog
. Thanks for any pointers or suggestions.This world is going to explode due to international politics, SOON.
-
hello guys... I have a small component from which I got a
wrapper (.tlb)
by importing and installing the component. I dropped the component from toolbox toTMainFormDialog
and got events. But I want to redirect these events to some other class NOT theTMainFormDialog
. Now I am , well sort of, not moving forward. Well I am not sure but I think I should be able to do this using RTTI. I think I should make and assign new properties (THE events) to the old ones. This is the psuedo-code that I tried.TServer = class (TOleServer)
private
FOnEventEx : TNotifyEvent; // new one
FOnEvent : TNotifyEvent; // old onepublished
property OnEventEx : TNotifyEvent read FEventEx write FEventEx ; // new one
property OnEvent: TNotifyEvent read FEvent write FEvent; // old onepublic
procedure FireThisProc(); // This is the event I want to be fired ----------- based on new property 'OnEventEx'.
end;Now I tried the
GetMethodProc()
andSetMethodProc()
in theCreate
function of .tlb wrapper like this but could not succeed.class function CoServer : IServer
begin
MethodProp := GetMethodProp(TObject(TServer), 'OnEventEx');
SetMethodProp(TObject(TServer) , 'OnEvent', MethodProp);Result := CreateComObject(CLASS_Server) as IServer;
end;So what (and how) should I do it exactly so that I might be able to redirect my events to some other class, NOT the
TMainFormDialog
. Thanks for any pointers or suggestions.This world is going to explode due to international politics, SOON.
Is RTTI the only way to do? Check if TMethod.Code contains empty info. and you're redirecting properties on TServer class, not a TServer object.
if MethodProp.Code <> Nil then
begin
//Sometimes OutputDebugString is neat for debugging components/pkg
OutputDebugString('Property Found.');
SetMethodProp(TObject(TServer) , 'OnEvent', MethodProp);
end
else
begin
OutputDebugString('Property Not Found.');
end;