X# Feature: Scoped classes

Public forum to share code snippets, screen shorts, experiences, etc.
Post Reply
User avatar
wriedmann
Posts: 3677
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

X# Feature: Scoped classes

Post by wriedmann »

Hello,

it is now the second consecutive day I'm using a language feature that is new to X# (and that maybe most people coming from VO does not knows):

Code: Select all

class MyClass
....
  class MyDetailClass
  ...
  end class

end class
The beauty is that the class MyDetailClass is visibile only in the MyClass itself, and not externally to it.

I'm using that instead of using multidimensional arrays, and I think this makes code much clearer.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4330
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

X# Feature: Scoped classes

Post by robert »

Wolfgang,

Yes this works. And you can use both List<MyDetailClass> as well as ARRAY OF MyDetailClass syntax

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 3677
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

X# Feature: Scoped classes

Post by wriedmann »

Hi Robert,

I prefer the array of MyDetailClass because I can use ASort() and AScan() then - I need both.
I know that you don't agree, but ASort() and AScan() as so powerful that I have found no corresponding possibility with the List collection class.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3677
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

X# Feature: Scoped classes

Post by wriedmann »

Hi Robert,

in my testclass this works:

Code: Select all

class MyExternalClass
	protect _aData			as array of MyInternalClass

  class MyInternalClass

  	constructor()

  end class

end class
but unfortunately it gives an error in my real code:

Code: Select all

error XS0310: 'clsTechnikerStatistik.TechnikerStatistikDetail' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 'XSharp.__ArrayBase<T>'
The class TechnikerStatistikDetail has a public parameterless constructor.....

Code: Select all

class TechnikerStatistikDetail
public constructor()
    self:Aufnr := 0
    return

public property Aufnr as int auto
end class
I'm will try to reproduce this in my sample class.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply