I'd like to write test code to parse through it and test to ensure that
(for example) the OnClick is assigned on every TButton - AND list the
actual assigned method name.
I'm a bit sleep-deprived right now - seems to me that should be fairly
straightforward but it escapes me at the moment.
Any suggestions?
TIA
Cheers,
EdB
> I'd like to write test code to parse through it and test to ensure that
> (for example) the OnClick is assigned on every TButton - AND list the
> actual assigned method name.
> I'm a bit sleep-deprived right now - seems to me that should be fairly
> straightforward but it escapes me at the moment.
You can get all event handlers linked to component events by using RTTI:
For each component on a form, for each property of tkMethod do
get the TMethod it is bound to and use Form.GetMethodName(pointer)
to display the connected name.
The other way round: make sure that all eventhandlers are connected
to some component requires parsing the source.
You could also install the free ModelMaker Code Explorer demo.
http://www.modelmakertools.com/code-explorer/download.html
This has an eventhandler analysis window that does exactly what you need.
You can see the relations between components, events and eventhandlers
in a life windows + report to file / clipboard etc.
Here is a demo movie of the event handler view:
http://modelmakertools.com/movies/event-handlers-view.htm
The free demo gives you 29 days to re-work this form...
But be warned: there are many more features in MMX that are
highly addictive ;-)
Gerrit Beuze
ModelMaker Tools
> You can get all event handlers linked to component events by using
RTTI:
>
> For each component on a form, for each property of tkMethod do
> get the TMethod it is bound to and use Form.GetMethodName(pointer)
> to display the connected name.
My first attempt last night (this morning, I guess) with PropInfo kept
reporting 'OnClick' - not real useful <g>.
> You could also install the free ModelMaker Code Explorer demo.
> http://www.modelmakertools.com/code-explorer/download.html
Oh, and you *happen* to have a sale on... <g>
Oh, wait - that's for MM9. Curses!
EdB
> My first attempt last night (this morning, I guess) with PropInfo
> kept reporting 'OnClick' - not real useful <g>.
You are retreiving the name of the event itself, not the name of the event
handler that is currently assigned to the event. You have to retrieve the
event's current value via GetMethodProp(), and then you can resolve the
returned TMethod pointer to a method name via TObject.MethodName(). For
example:
var
M: TMethod;
MName: String;
begin
M := GetMethodProp(TheObject, PropInfo);
if (M.Data <> nil) and (M.Code <> nil) then
MName := TObject(M.Data).MethodName(M.Code);
end;
Gambit