[Gambas-user] Static Classes and Modules

John Leake jleake at ...3375...
Sat Sep 20 11:55:06 CEST 2014


Thanks Tobi,
>> So could someone tell me if a class without any dynamic variable ie a
>> static class, can or cannot be created ?
>>
> 
> Or you can try it out.
> 
> What I did was creating a module and making objects from it with New -- it
> works, but those objects are even more limited than I had expected. In their
> code, there seems to be no way to even see that they are any different from
> the automatic instance (singleton). The module's code was:
> 
> --8<--[ Module1.module ]----------------------------------------------------
> ' Gambas module file
> 
> Public Sub Print()
>   Print Me
> End
> --8<------------------------------------------------------------------------
> 
> and the program:
> 
> --8<--[ MMain.module ]------------------------------------------------------
> ' Gambas module file
> 
> Public Sub Main()
>   Dim h As New Module1, g As New Module1
> 
>   Print Module1
>   Module1.Print()
>   Print "---"
>   Print h
>   h.Print()
>   Print "---"
>   Print g
>   g.Print()
> End
> --8<------------------------------------------------------------------------
> 
> with the output:
> 
>   (Class Module1)
>   (Class Module1)
>   ---
>   (Module 0x...b8)
>   (Class Module1)
>   ---
>   (Module 0x...e8)
>   (Class Module1)
> 
> So indeed, there are different objects (especially, it's possible to
> instantiate modules) but "Me" inside the module code always refers to
> the singleton.
> 
This is where I have a problem h and g are different.




More information about the User mailing list