Delphi – finding published event handlers that have lost their binding from the DFM
Posted by jpluimers on 2018/05/15
The scripts in these links didn’t work well enough for me:
- [WayBack] Q: Is there a tool to find code that was written as an event-handler, but decoupled in the DFM – Vin Colgin – Google+Bash script at [WayBack] http://pisil.de/events.txt and [WayBack] http://pisil.de/wsl_events_2.txt
- via: [WayBack] Is there a tool that matches published methods on designers to actually have events hooked to them? – Jeroen Wiert Pluimers – Google+
So I’ve been working on a GExperts based solution (because that gave me a nice starting point). It’s not fully done yet, so here are a few things I’ve used:
- [WayBack] Hallvard’s Blog: Hack #10: Getting the parameters of published methods
- The streaming mechanism looks for published methods in the RTTI that have a name equal to the event in the stream and a signature matching the event type.The default section by definition has visibility published for anything compiled in $M+ mode (which is enabled for TPersistent and inherits to descendants).
- The ancient [WayBack] TReader.FindMethodInstance Method that is now at [WayBack] System.Classes.TReader.FindMethodInstance – RAD Studio API Documentation
function FindMethodInstance(Root: TComponent; const MethodName: string): TMethod; virtual;
- a
(Reminder to self: contact David Hoyle who knows a lot about the OTA).
–jeroen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Be careful with scripts, always do your backup or play on a copy | |
| # Finding abandoned events | |
| for i in `find . -name "*.pas" -type f`; do if [ -f ${i%.*}.dfm ]; then cat $i | grep "(Sender: TObject" | grep -v "\." | sed -e "s/\(.*\)\ \(.*\)(\(.*\)/\2/g" | xargs -n1 -I @@ sh -c "echo -n \"${i%.*}.dfm->@@: \"; grep -s -c @@ ${i%.*}.dfm" |grep ": 0"; fi; done | |
| # Finding events with every other occurence than "1" | |
| for i in `find . -name "*.pas" -type f`; do if [ -f ${i%.*}.dfm ]; then cat $i | grep "(Sender: TObject" | grep -v "\." | sed -e "s/\(.*\)\ \(.*\)(\(.*\)/\2/g" | xargs -n1 -I @@ sh -c "echo -n \"${i%.*}.dfm->@@: \"; grep -s -c @@ ${i%.*}.dfm" |grep -v ": 1"; fi; done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # !!! Be careful with scripts, always do your backup or play on a copy !!! | |
| # Finding abandoned events v2 | |
| for i in `find . -name "*.pas" -type f`; do if [ -f ${i%.*}.dfm ]; then cat $i | \ | |
| sed -nr "/=(\s)*class/I,/(private|protected|public|published|automated)/I{p}" | \ | |
| sed -nr "/procedure/Ip" | \ | |
| sed -e "s/\(.*\)\ \(.*\)(\(.*\)/\2/g" | \ | |
| xargs -n1 -I @@ sh -c "echo -n \"${i%.*}.dfm->@@: \"; grep -i -s -c @@ ${i%.*}.dfm" | \ | |
| grep ": 0"; fi; done |






Leave a comment