修改VCL组件代码 [英] Modifying VCL Component CODE

查看:65
本文介绍了修改VCL组件代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更改组件中的功能。当收到您无法覆盖此消息消息时,或者您需要更改私有方法中的代码(方法在基类中不存在消息)时,该怎么办,使该组件无法下降?

I need to change the functionality in a component. What do you do when you get a "you can't override this" message, or you need to change the code in a private method ("method does not exist in base class" message), rendering it impossible to descend the component?

推荐答案

如果遇到此问题,


  • 我首先尝试从组件或其CustomXXX祖先继承,看看是否可以解决问题。如果不是这样,

  • 我会更深入,即尝试拦截传入的消息。这可以动态完成。如果结果太深,因为必须建立在上面的代码太广泛,或者如果我仍然必须访问我无法访问的项目,则

  • 我尝试骇客。一种技巧是将组件和相关代码复制到一个具有不同名称的新单元中,重命名组件并修改需要修改的内容。

  • 有时我只需要重做一个或有两种方法可以使我的新行为成为可能。

  • I first try to inherit from the component, or its CustomXXX ancestor and see if that fixes the problem. If that doesn't,
  • I go deeper, i.e. try to intercept the messages that come in. That can be done dynamically. If that turns out to be too deep, because the code that has to be built on that is too extensive, or if I still have to access items I can't access,
  • I try hacks. One hack is to copy the component and the dependent code to a new unit with a different name, rename the component and modify what needs to be modified.
  • Sometimes I only need to redo one or two methods to make my new behaviour possible.

永远不要忘记给单元一个不同的名称,并且给该组件一个不同的名称(可能继承自原始组件或其中一个组件)祖先,因此它们保持在相同的层次结构中)。 从不修改原始源,然后重新编译VCL。这是维护方面的噩梦。

Never forget to give the unit a different name and the component a different name too (possibly inheriting from the original component or one of its ancestors, so they remain in the same hierarchy). Do never modify the original sources and then recompile the VCL. That is a maintenance nightmare.

我不喜欢插入器类,即从原始类继承而来的名称与原始类相同但行为不同的类。它们的功能取决于uses子句中的包含顺序,这在我看来似乎很薄弱。我不建议这样做。

I am no fan of interposer classes, i.e. classes that get the same name but different behaviour than the original classes, inheriting from the original. Their functionality depends on the order of inclusion in the uses clause, and that seems rahter flaky to me. I can't recommend that.

但是我的工作很大程度上取决于问题。我认为没有人可以(或应该)提供涵盖所有情况的全面建议。

But what I do greatly depends on the problem. I don't think one can (or should) give a blanket advice that covers all situations.

但是我的主要建议: 请勿修改原始单位 ,请始终将新代码放在新单位中,并使用新类名。这样,原始版本和修改后的版本就可以在IDE中和平共存。

But my main advice: do not modify the original units, always put the new code in a new unit and use a new class name. That way the original and the modified versions can peacefully co-exist, also in the IDE.

这篇关于修改VCL组件代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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