views:

84

answers:

1

I use Bold for Delphi with D2007. The model is rather big and now I discover we have many methods in the model that are not called. The compiler should give a hint about it but it is quiet.

In Delphi the linker remove methods that do not have any reference. It then give a hint on that when compiling. I try to explain how Bold use methods in the model.

One unit BusinessClasses.pas includes hundreds of files like this:

{$INCLUDE BusinessClasses_Interface.inc}
{$INCLUDE Quantity.inc}
{$INCLUDE Parcel.inc}
// and so on...

The file BusinessClasses_Interface.inc contains this:

TParcel = class(TOrderItem)
public
  procedure WayBillAsXML(var aXMLstring: string);
end;

Then parcel.inc have the actual method implementation:

procedure TParcel.WayBillAsXML(var aXMLstring: String);

I think if I don't call WayBillAsXML then I should get a hint from the compiler but it is quiet about that. Ideally I want a list of all code that is not referenced. Is there a way ?

+3  A: 

The compiler doesn't show you a hint because the method is public and so some other code could call it. The same is for protected methods. Another (package-)unit could have a class that derives from your class and this derived class could call the method.
The Delphi linker isn't smart enough to recognize that the method isn't called in your whole project. It treats EXE/DLL files and BPL files the same. But only the later would allow other code to call the method whereas it could remove the method for EXE/DLL files.

Andreas Hausladen
So there isn't a way to list all unused methods ? BTW, I found a manual procedure. In debug mode there is blue dots only in methods that are used. But this is very cumbersome method for checking in a big project like this.
Roland Bengtsson
you could temporarily change their visibility to private, anything the compiler complains about as "unidentified" you put back to protected/public (whatever it was before), anything that is not used the compiler should then hint about.
Marjan Venema
Thanks, that was clever! At least it is a bit easier than my method with Debug mode. But you should put this as an answer instead of comment otherwise I cannot up vote you.
Roland Bengtsson