The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,311 other followers

Oh nice. Feel free to QP. E2003WithConstsInDescendingClassesConsoleProject

Posted by jpluimers on 2017/12/06

Oh nice. Feel free to QP. Fails at least in Delphi XE8.

program E2003WithConstsInDescendingClassesConsoleProject;

{$APPTYPE CONSOLE}

uses
ParentUnit in 'ParentUnit.pas',
ChildUnit in 'ChildUnit.pas';

begin
end.
unit ParentUnit;

interface

type
  TParent = class
  // section can be strict protected, protected, public, published or nothing
  const
    InitialBooleanValue = False;
    InitialIntegerValue = -1;
  end;

implementation

end.
unit ChildUnit;

interface

uses
  ParentUnit;

type
  TChild = class(TParent)
  // section can be strict protected, protected, public, published or nothing
  const
//    Initial and final values need to be different to test the behaviour
    FinalBooleanValue = not InitialBooleanValue;
    FinalIntegerValue = InitialIntegerValue + 1;
//[dcc32 Error] ChildUnit.pas(13): E2003 Undeclared identifier: 'InitialBooleanValue'
//[dcc32 Error] ChildUnit.pas(14): E2003 Undeclared identifier: 'InitialIntegerValue'
//[dcc32 Error] ChildUnit.pas(14): E2026 Constant expression expected
  end;

implementation

end.

[WayBackOh nice. Feel free to QP. unit ParentUnit; interface type TParent = class …

3 Responses to “Oh nice. Feel free to QP. E2003WithConstsInDescendingClassesConsoleProject”

  1. Been there too, I know the answer in QP “closed as designed”.

    As a workaround use TParent.*

    TChild = class(TParent)
      const
        FinalBooleanValue = not TParent.InitialBooleanValue;
        FinalIntegerValue = TParent.InitialIntegerValue + 1;
      end;
    • jpluimers said

      Thanks. I should have included the workaround, so thanks for posting that.

    • rvelthuis said

      That is not a “workaround”. That is how nested constant and type declarations work. It was your expectation (that they are somehow inherited and can be accessed without qualification) that was wrong.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: