Should descendent be able to invoke ancestor's class method?

I have this in 3 separate files in one project:

file1:

   type
      TaggedStrings = public class
         public
            class function  DoReplacements( useSettings : Settings; s : String; isLoginWelcomeLabel : boolean ) : String; 
         end;

file2:

   type
      LocalizationBase = public class( TaggedStrings )
         public
          ...
         end;

file3:

   type
        StringProperties = public class( LocalizationBase )
         public
            ...
            class function  GetSubstitutedString( key : String ) : String; override;
            ...
         end;

And this implementation for the StringProperties method:

   class function StringProperties.GetSubstitutedString( key : String ) : String;
      begin
         ...
         result := DoReplacements( GlobalSettings, GlobalSettings.StringLibrary[ key ], false );
         ...
      end;

When I compile it, I get:

Error 9 (PE9) Unknown identifier “DoReplacements”

If I JUST add the keyword “virtual” to the end of the DoReplacements declaration, it compiles fine.

Is this a bug? I would have thought that the descendent class would inherit the ancestor’s class method WITHOUT the virtual keyword and that the virtual would just allow for the overriding in the descendent. I didn’t expect the LACK of a virtual to HIDE the ancestor’s method.

Hello,

Sorry but I cannot reproduce your problem here. Could you please send us a simple testcase that shows the problem.

Thanks in advance.

On first blush, I can’t reproduce it either. Must have been some other piece I left out. I see I didn’t give the Virtual routine for the one that had the override. But what I gave was an actual copy and paste for what didn’t work. I’ll see if I can get whatever else is there to reproduce it. There is a fair amount of other code, so I’m hesitant to give you the whole thing, but I might do that.

Okay, here is one that exhibits the problem.

Apparently, the problem happens when the “middle” class has that virtual method.

Mark,
with version .1381, I compile your project without any error. Which version of the compiler do you use?
Patrick

Yeah, I wondered if it was this older version I am using. Hopefully when I get this project at a good stopping point, I can upgrade. I’ll look up the version as soon as it loads again as it just hung up. It often hangs up after a full build and then compiling just a single project. Hopefully that behavior will go away too.

Here is ALL the info:

Microsoft Visual Studio 2010
Version 10.0.40219.1 SP1Rel
Microsoft .NET Framework
Version 4.0.30319 SP1Rel

Installed Version: Professional

Microsoft Office Developer Tools 01018-532-2002102-70042
Microsoft Office Developer Tools

Microsoft Visual Basic 2010 01018-532-2002102-70042
Microsoft Visual Basic 2010

Microsoft Visual C# 2010 01018-532-2002102-70042
Microsoft Visual C# 2010

Microsoft Visual C++ 2010 01018-532-2002102-70042
Microsoft Visual C++ 2010

Microsoft Visual F# 2010 01018-532-2002102-70042
Microsoft Visual F# 2010

Microsoft Visual Studio 2010 Team Explorer 01018-532-2002102-70042
Microsoft Visual Studio 2010 Team Explorer

Microsoft Visual Web Developer 2010 01018-532-2002102-70042
Microsoft Visual Web Developer 2010

AnkhSVN - Subversion Support for Visual Studio 2.4.11610.27
AnkhSVN - Subversion Support for Visual Studio 2.4.11610.27

  • Ankh.Package 2.4.11610.27
  • Subversion 1.7.6 via SharpSvn 1.7006.2206.13750

SharpSvn is linked to: Apr 1.4.6, Apr-util 1.4.2, Cyrus Sasl 2.1.23, Neon 0.29.6, OpenSSL 1.0.1c 10 May 2012, serf 1.1.0, SQLite 3.7.12.1, Subversion 1.7.6-SharpSvn-1.7.6, ZLib 1.2.7
SharpSvn is optionally linked to: Berkeley DB 4.4.20, SharpPlink 1.7006.2206.13750

Crystal Reports Templates for Microsoft Visual Studio 2010
Crystal Reports Templates for Microsoft Visual Studio 2010

Embarcadero Delphi Prism 4.0.27.843
Embarcadero Delphi Prism
Powered by the RemObjects Oxygene Compiler
Copyright © 2008-2010 Embarcadero Technologies, Inc. All rights reserved.
All Embarcadero brand and product names are trademarks or registered trademarks of Embarcadero Technologies, Inc. in the United States and other countries. Oxygene is a trademark of RemObjects Software, LLC in the United States and other countries. All other marks are the property of their respective owners.

Dedicated to Rick Wright (1943-2008).
Enjoy the Great Gig in the Sky.

Entity Framework 4.1 Power Tools 1.0
Adds useful design-time DbContext features to the Visual Studio Solution Explorer context menu.

When right-clicking on a file containing a derived DbContext class, the following context menu functions are supported:

  1. View Entity Data Model - Displays the underlying Code First model in the Entity Framework designer.
  2. View Entity Data Model XML - Displays the EDMX XML representing the underlying Code First model.
  3. Optimize Entity Data Model - Generates pre-compiled views used by the EF runtime to improve start-up performance. Adds the generated views file to the containing project.

Hotfix for Microsoft Visual Studio 2010 Professional - ENU (KB2529927) KB2529927
This hotfix is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2529927.

Hotfix for Microsoft Visual Studio 2010 Professional - ENU (KB2548139) KB2548139
This hotfix is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2548139.

Hotfix for Microsoft Visual Studio 2010 Professional - ENU (KB2549864) KB2549864
This hotfix is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2549864.

Hotfix for Microsoft Visual Studio 2010 Professional - ENU (KB2565057) KB2565057
This hotfix is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2565057.

Hotfix for Microsoft Visual Studio 2010 Professional - ENU (KB2635973) KB2635973
This hotfix is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2635973.

Hotfix for Microsoft Visual Studio 2010 Professional - ENU (KB2736182) KB2736182
This hotfix is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2736182.

Hotfix for Microsoft Visual Studio 2010 Professional - ENU (KB2813041) KB2813041
This hotfix is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2813041.

Microsoft Visual Studio 2010 Professional - ENU Service Pack 1 (KB983509) KB983509
This service pack is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this service pack will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/983509.

Microsoft Visual Studio 2010 SharePoint Developer Tools 10.0.40219
Microsoft Visual Studio 2010 SharePoint Developer Tools

NuGet Package Manager 1.4.20615.9020
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Oracle Developer Tools for Visual Studio 11.2.0.1.2
Oracle Developer Tools for Visual Studio Copyright © 2005, 2010

RemObjects Everwood 3.0.17.257
RemObjects Everwood for .NET
Copyright 2003-2010 RemObjects Software, LLC. All rights reserved.
http://www.remobjects.com/everwood

RemObjects Oxygene 4.0.27.843
RemObjects Oxygene
Copyright 2003-2011 RemObjects Software, LLC. All rights reserved.
http://www.remobjects.com/oxygene

Security Update for Microsoft Visual Studio 2010 Professional - ENU (KB2645410) KB2645410
This security update is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this security update will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2645410.

SQL Server Data Tools 10.3.20905.0
Microsoft SQL Server Data Tools

VisualStudioIntegration2010 1.0
Information about my package

VMDebugger
For more information about VMware Inc, see their website at


Copyright © 2010 VMware, Inc.

Hello,

I tested your project with latest Oxygene and indeed the problem is not reproduced in it.
Also latest oxygene doesn’t support VS2010, only 2012 and 2013.

Best regards.

Thanks for checking. Yeah, I was just talking to my boss in the last couple of days that we should try using 2012 or 2013, but we are in the middle of some major changes so we can’t risk changing at the moment.

viktoriad,

I assume you tried REMOVING the virtual in the class in file1 for your test, right?

I’m afraid I didn’t. I only compiled the attached project and the compiling was fine. However I opened the project again and tried to remove virtual, override keywords and recompile it again. Also success.
What could I possibly miss?

I assumed you were following along with the discussion. I guess I should have given you a version that failed. It sounds like you removed all virtual and overrides. That would remove the problem. AS I SAID, if you JUST remove the virtual from the class in FILE 1, that produces the error for me.

I’ll recreate it WITH the error in place and re-zip it and re-upload it so that you will be sure to test it in a state that fails for me.

Will upload momentarily.

Here it is and it fails to compile for me as it is.

Hello,

I retested the project you uploaded and still I have no errors. You have quite old Oxygene version if you are using it with VS2010 so the newer one solved the issue.

Best regards.

ok. Thanks.