views:

114

answers:

1

In one of my component sets, I am getting a number of warnings at compile time: "Method Create (Clear, DrawTab) hides virtual method of base type ControlX". My problem is that I don't know enough about virtual methods and Delphi to know how to fix this properly (we have the source code). Does anyone know how to fix this type of error in Delphi 5? Thanks.

+9  A: 

You need to mark the method with override:

function Create(clr :Clear; dt : DrawTab); override;

This flags that you're overriding the base class version.

Reed Copsey
Only do this if you intend to override the virtual method. If you intend to replace it, use "reintroduce" instead.
Mason Wheeler
@Mason: Very true. @Tom: In this case, since you're "creating" a "control", you probably want to override and call the base class version - that would be the more common usage.
Reed Copsey
"override" only works if the original method is virtual (which it is) *and* the parameters are the same. As suggested above, if you want to replace the method, use "reintroduce" - if you want an alternative method with the same name, then use "overload".
Alistair Ward
Exactly. Tell the compiler that you know what you're doing and it's not a mistake. Delphi often hints or warns on suspicious but compilable stuff--something I think is good. I've never found a message I can't get rid of, albeit occasionally at the cost of a meaningless assignment when the compiler can't see that all paths assign a value, or that if it's not assigned it won't be used.
Loren Pechtel
override works in two cases here, and needed the inherited for the create, but I needed the reintroduce keyword for the other two. I hadn't known about that before. Thanks Everyone.
Tom