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

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

问题描述

我正在使用 Delphi Pro 6.现在,知道一个类是否缺少基类抽象方法的唯一方法是等待 IDE 发出一个{派生类} 的构造实例,其中包含抽象方法 {base class.abstract method name}"警告或在尝试调用丢失的方法时等待运行时抽象错误方法.前者是不够的,因为它只为当前项目中实际构建的那些派生类找到警告.后者简直就是痛苦.

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?

谢谢.

推荐答案

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

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);
  TAbstractClass1.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天全站免登陆