BCB窗体的TForm类,能不能再继承自定义的类?
创建一个Form默认为TForm1,继承为class TForm1 : public TForm
自定义一个类MyClass
想TForm1继承MyClass class TForm1 : public TForm,public MyClass
但是不行,说不是抽象的,难道不能这样继承?
反过来继承是可以的
MyClass : public TForm1
[解决办法]
vcl 不支持多重继承
[解决办法]
换成接口试试
[解决办法]
学习一下
[解决办法]
我的理解是,是VCL就不支持,因为即使继承类用CB来写,你的基类也是Delphi的
[解决办法]
TForm类是一个VCL类,它的最初定义为DELPHICLASS也就是BCB特有的__declspec(delphiclass)
看它的HELP
The delphiclass argument is used for declarations for classes derived from TObject. These classes will be created with the following compatibility:
Object Pascal-compatible RTTI
VCL (CLX)-compatible constructor/destructor behavior
VCL (CLX)-compatible exception handling
A VCL or CLX-compatible class has the following restrictions:
No virtual base classes are allowed.
No multiple inheritance is allowed except for the case described in Inheritance and interfaces.
Must be dynamically allocated by using the global new operator.
Must have a destructor.
Copy constructors and assignment operators are not compiler-generated for VCL-or CLX- derived classes.
A class declaration that is translated from Object Pascal will need this modifier if the compiler needs to know that the class is derived from TObject.
它兼容DELPHI(O-PASCAL)类,是不支持多种继承的
[解决办法]
不过说到这里呢。 我觉得TForm 有没有继承的必要.它就是一个VIEW.
你要是定义好了你的程序的主要的VIEW风格,可以一个个继承过来. TForm TMainForm TStyleForm
等等.
你业务逻辑的 或者其他的就不要勉强到VIEW里面来了. 换个想法HAS-A呢。
在你的窗体里面执行一个业务逻辑的相关处理. 呵呵.