列出没有引用的代码
我将 Delphi 的 Bold 与 D2007 一起使用。该模型相当大,现在我发现模型中有许多未调用的方法。编译器应该给出一个提示,但它很安静。
在 Delphi 中,链接器删除没有任何引用的方法。然后它会在编译时给出提示。我尝试解释 Bold 如何在模型中使用方法。
一个单元 BusinessClasses.pas 包含数百个这样的文件:
{$INCLUDE BusinessClasses_Interface.inc}
{$INCLUDE Quantity.inc}
{$INCLUDE Parcel.inc}
// and so on...
文件 BusinessClasses_Interface.inc 包含以下内容:
TParcel = class(TOrderItem)
public
procedure WayBillAsXML(var aXMLstring: string);
end;
然后 Parcel.inc 具有实际的方法实现:
procedure TParcel.WayBillAsXML(var aXMLstring: String);
我认为如果我不调用 WayBillAsXML 那么我应该从编译器获得提示,但它对此很安静。理想情况下,我想要一个未引用的所有代码的列表。有办法吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编译器不会向您显示提示,因为该方法是公共的,因此其他一些代码可以调用它。对于受保护的方法也是如此。另一个(包)单元可以有一个从您的类派生的类,并且该派生类可以调用该方法。
Delphi 链接器不够智能,无法识别整个项目中没有调用该方法。它将 EXE/DLL 文件和 BPL 文件视为相同。但只有后者才允许其他代码调用该方法,而它可以删除 EXE/DLL 文件的方法。
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.