开发者

List code without reference

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.

开发者_如何学Python

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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜