Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not aware of a preexisting app or plugin to do this, but it shouldn't be hard to script.</p> <p>Assuming you're not using RTTI or manually assigning event handlers: (I'm a C++Builder user rather than Delphi, so the following may not be quite correct.)</p> <ol> <li>Make a list of all published methods in your code. <ul> <li>The proper way to do this is to read <code>*.pas</code>. Find each text block that starts with a <code>class</code> declaration or a <code>published</code> directive and ends with a <code>end</code>, <code>private</code>, or <code>public</code>. Within each of these text blocks, extract each <code>procedure</code>.</li> <li>The easy way to do this is to make a list of common event handler types and assume they're published.</li> </ul></li> <li>Once you have this list, print everything from the list that's not found in your DFM file.</li> </ol> <p>I'm most comfortable using Cygwin or Linux tools for scripting. Here's a bash script that works in Cygwin and should do what you want.</p> <pre><code>#!/bin/bash for file in `find -name *.pas`; do echo $file: # Get a list of common event handling procedures. # Add more types between the | symbols. egrep '^[[:space:]]+procedure.*(Click|FormCreate|FormClose|Change|Execute)\(' $file | awk '{print $2}' | cut -f 1 -d '(' &gt; published.txt # Get a list of used event procedures. egrep '^[[:space:]]+On.* =' ${file%.pas}.dfm | awk '{print $3}' &gt; used.txt # Compare the two. # Files listed in the left column are published but not used, so you can delete them. # Files in the right column were not by our crude search for published event # handlers, so you can update the first egrep command to find them. comm -3 published.txt used.txt echo done # Clean up. rm published.txt used.txt </code></pre> <p>To actually use this, if you're not familiar with Cygwin:</p> <ul> <li>Download and install Cygwin. I <em>think</em> the default install should give you all of the tools I used, but I'm not positive.</li> <li>Save the script to your source directory as <code>cleanup.sh</code>.</li> <li>Start a Cygwin command prompt.</li> <li>If your source is in c:\MyApp, then type <code>cd /cygdrive/c/myapp</code></li> <li>Type <code>./cleanup.sh</code> and press Enter.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload