VCL多重继承
我正在尝试开发一组控件,它们在大小调整方面都有许多常见的行为。我认为这是一个需要多重继承的实例(尽管我完全愿意接受任何相反的建议)。我想做的基本上是混合模式
class Sizable {
...
public:
ResizeMe();
ResetText();
...
};
class sizeButton : public Sizable, public TButton {
...
};
class sizeEdit : public Sizable, public TEdit {
...
};
等等...
我已经在 Sizing 类中编写了大量的大小调整代码并对其进行了测试,它很好,但现在我已经列出了结构的其余部分(是的,我可能应该先为类编写一个框架)并且遗憾地发现:
[BCC32 Error] szButton.h(15): E2278 Multiple base classes not supported for VCL classes
我已经取出了所有不需要是成员函数的函数(例如测量字符串的长度),但仍然有很多功能这是不可能的。
有没有人有任何设计建议,这样我就不必重复大量代码?
I'm trying to develop a set of controls which all have a number of common behaviours with respect to sizing. I think that this is an instance where multiple inheritance is required (although am fully willing to accept any advice to the contrary). What I would like to do is basically a mixin pattern
class Sizable {
...
public:
ResizeMe();
ResetText();
...
};
class sizeButton : public Sizable, public TButton {
...
};
class sizeEdit : public Sizable, public TEdit {
...
};
and so forth...
I have written a non-trivial amount of sizing code in the Sizable class and tested it and it's nice, but now I have set out the rest of the structure (yes, I probably should have written a skeleton for the classes first) and have discovered that sadly:
[BCC32 Error] szButton.h(15): E2278 Multiple base classes not supported for VCL classes
I have pulled out all the functions which aren't required to be member functions (e.g. measuring the length of strings), but there are still a lot of functions where this is not possible.
Does anyone have any design advice so that I don't have to duplicate a ton of code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Delphi(以及主要用Delphi 编写的VCL)不支持类的多重继承。然而,从 v6 开始,当使用 VCL 类作为祖先时,它确实支持接口的多重继承,例如:
Delphi (and thus the VCL, which is mostly written in Delphi) does not support multiple inheritance of classes. However, in v6 onwards, it does support multiple inheritance of interfaces when a VCL class is used as an ancestor, for example:
为什么不让
TButton
成为一个成员(组合)而不是继承它?Why not make the
TButton
a member (composition) rather than inherit from it?