Delphi 6:在缺少抽象类方法的情况下强制编译器出错? [英] Delphi 6: Force compiler error on missing abstract class methods?

查看:80
本文介绍了Delphi 6:在缺少抽象类方法的情况下强制编译器出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Delphi Pro6.现在,知道类是否缺少基类抽象方法的唯一方法是等待IDE发出包含抽象方法{的{derived class}的构造实例"尝试调用缺少的方法时,警告或等待运行时Abstract Error方法.前者是不够的,因为它只为当前项目中实际构造的派生类找到警告.后者简直就是痛苦.

I'm using Delphi Pro 6. Right now, the only way to know if a class is missing a base class abstract method is to wait for the IDE to emit a "constructing instance of {derived class} containing abstract method {base class.abstract method name}" warning or to wait for a runtime Abstract Error method when an attempt to call the missing method is made. The former isn't sufficient since it only finds warnings for those derived classes actually constructed in the current project. The latter is just plain painful.

如果Delphi为所有不立即声明/实现基类抽象方法的类输出致命警告,那就更好了.有谁知道设置方法或执行此操作的插件?

It would be so much better if Delphi output a fatal warning for all classes that do not declare/implement a base class abstract method immediately. Does anyone know a way to set this up or a plug-in that does this?

谢谢.

推荐答案

我发现最简单的方法是使用条件定义在单元初始化区域中添加一个部分,该条件定义可为您创建的每个类创建一个实例认为不应该有任何抽象方法:

I've found the simplest way to do this is to add a section in the unit initialization area using a conditional define that creates an instance of each class that you think shouldn't have any abstract methods:

{$IFDEF CheckAbstracts}
initialization
  TSubclass1.Create(params);
  TAbstactClass1.Create(params); // Gives constructing instance of {derived class} containing abstract method warning
{$ENDIF}

使用CheckAbstracts条件编译,当您实现的类不完整时,您将收到警告.

Compile with the CheckAbstracts conditional, and you will get warnings whenever you have an incompletely implemented class.

这篇关于Delphi 6:在缺少抽象类方法的情况下强制编译器出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆