0

I am almost done with migrating my software for .NET environment. Now I am going through all the warnings and cleaning them up. Then, I ran into this problem.

Here is my class:

 TColorObj = class
   value:double;
   thecolor:Color;
   Constructor;
   method ReadColor(bdr:BinaryReader);
   method WriteColor(bdw:BinaryWriter);
   method Clone:TColorObj;
   method ToString:String; Override;  <<<<----this method is raising error.
 end;

The error is "Cannot override method with lower access than base method." However, if I remove the key word, Override, it raises a warning message, "ToString" hides a parent method." TColorObj class is not inherited from any base class as you can see.

So, do I make the class TColorObj public?

Any help or hints will be appreciated.

Ken White
  • 123,280
  • 14
  • 225
  • 444
ThN
  • 3,235
  • 3
  • 57
  • 115

2 Answers2

4

You need to make the ToString method public in visibility, which is what it is in TObject. You can't move it from 'public' to a lower visibility in a descendant.

TColorObj = class
   value:double;
   thecolor:Color;
   Constructor;
   method ReadColor(bdr:BinaryReader);
   method WriteColor(bdw:BinaryWriter);
public
   method Clone:TColorObj;
   method ToString:String; Override;  <<<<----this method is raising error.
end;
Ken White
  • 123,280
  • 14
  • 225
  • 444
1

Every class is inheriting from another class, if you don't specify a class you are inheriting from the Object class.

You are overrinding the ToString method which is public, so you have to make the overriding method public also.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005