Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-01

Nested Classes used as Namespace Question

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andrew Brunner
  Type
    NS_APP=class
      const
        const1=2;
        const3=5;
      type
        NS_SPACE1=class
          type
            Properties=(Name,Value);
            TMyRecord=record
              ID : integer;
              Name:string;
              Value:string;
            end;
        end;
        NS_SPACE2=class
          type
            Properties=(Name,Value); // Duplicate Identifer "Name"
error @ compile
            TMyRecord=record
              Key : Array[0..1] of Byte;
              Value : Pointer;
            end;
        end;
    end;

I'm trying to have identical naming conventions and kind of expected these classes to have some degree of isolation within nests. NS_SPACE2.Properties.Name is not valid b/c the compiler has Name already defined above in NS_SPACE1. Is this expected? Is it too much work to isolate nested classes so I can get past this error? Is there another way to achieve having two "Properties" type with two different types with no exceptions?

Thanks in advance.

Reply by email

Andrew Brunner
to Andrew Brunner

As a follow-up I've temporarily got past this issue by making each member of the enumeration having a unique name with a preceding character. The only problem now is my code looks well not as refined...

ns.App.Props.aName
ns.Vendor.Props.vName

Anyone want to give this a try at fixing ? I want to have nested enumerations isolated within classes with identical names ;-)

Reply by email

Paul Ishenin
to Andrew Brunner: Type NS_APP=class const const1=2; const3=5; type NS_SPACE1=class type…
Andrew Brunner wrote 25 lines
Type NS_APP=class const const1=2; const3=5; type NS_SPACE1=class type Properties=(Name,Value); TMyRecord=record ID : integer; Name:string; Value:string; end; end; NS_SPACE2=class type Properties=(Name,Value); // Duplicate Identifer "Name" error @ compile TMyRecord=record Key : Array[0..1] of Byte; Value : Pointer; end; end; end;

This is by design. Enumeration members are added both to the unit and enumration symbol table and therefore can't have equal names. If you want to prevent adding them to the unit symbol table use {$SCOPEDENUMS ON} directive. Then you will need to access them using prefixes only. Like NS_APP.NS_SPACE1.Properties.Name.

Best regards,
Paul Ishenin

Reply by email

Sven Barth
to Paul Ishenin
Paul Ishenin wrote 31 lines
10.01.2011 1:47, Andrew Brunner wrote: > Type > NS_APP=class > const > const1=2; > const3=5; > type > NS_SPACE1=class > type > Properties=(Name,Value); > TMyRecord=record > ID : integer; > Name:string; > Value:string; > end; > end; > NS_SPACE2=class > type > Properties=(Name,Value); // Duplicate Identifer "Name" > error @ compile > TMyRecord=record > Key : Array[0..1] of Byte; > Value : Pointer; > end; > end; > end; This is by design. Enumeration members are added both to the unit and enumration symbol table and therefore can't have equal names. If you want to prevent adding them to the unit symbol table use {$SCOPEDENUMS ON} directive. Then you will need to access them using prefixes only. Like NS_APP.NS_SPACE1.Properties.Name.

I should really enable some sort of notification for changes in the wiki pages "FPC New Features Trunk" and "User Changes Trunk"... then I won't miss the addition of such interesting features.

Regards,
Sven

Reply by email