Delphi 6:在缺少抽象类方法时强制编译器错误?

编程入门 行业动态 更新时间:2024-10-21 12:42:43
本文介绍了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:在缺少抽象类方法时强制编译器错误?

本文发布于:2023-11-08 13:58:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569571.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编译器   错误   方法   抽象类   Delphi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!