0

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?

0

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Only do this if you intend to override the virtual method. If you intend to replace it, use "reintroduce" instead.
@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.
"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".
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.
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.