Page 1 of 1

[4.02]EnableExplicit and Shared

Posted: Mon Dec 18, 2006 9:22 am
by HeX0R
I'm getting an error message Test wouldn't be declared:

Code: Select all

EnableExplicit

Procedure Dummy()
	Shared Test.POINT
	
EndProcedure

Posted: Mon Dec 18, 2006 9:34 am
by Flype
yes i can confirm this.

this works :

Code: Select all

EnableExplicit

Define Test.POINT

Procedure Dummy()
   Shared Test
   Debug Test\x
   Debug Test\y
EndProcedure 

Dummy()
Does this means that 'Shared' var should be defined once outside the procedure ? If so, maybe it's not a bug (?)

Posted: Mon Dec 18, 2006 1:10 pm
by jear
But this doesn't work.
So we are not able to share variables between procedures, without declaring it in the main program too.

Code: Select all

EnableExplicit 

Procedure Dummy_1() 
  Shared Test.POINT 
  
EndProcedure 

Procedure Dummy_2() 
  Shared Test.POINT 
  
EndProcedure 

Dummy_1()
Dummy_2()

Posted: Mon Dec 18, 2006 2:13 pm
by freak
This was changed to have a consistent behaviour with shared LinkedLists and Arrays,
where they need to be defined in the main source first as well.

Posted: Mon Dec 18, 2006 2:26 pm
by Flype
ok freak,

so, is this the good/clean syntax ?

Code: Select all

EnableExplicit

Define myPoint.POINT

Procedure Dummy1()
  Shared myPoint
  myPoint\x = 111
  myPoint\y = 222
EndProcedure

Procedure Dummy2()
  Shared myPoint
  Debug myPoint\x
  Debug myPoint\y
EndProcedure

Dummy1()
Dummy2()

Posted: Mon Dec 18, 2006 2:32 pm
by Flype
Hmmmm, i'm just wondering...

And what the use to 'Shared' a variable previously defined as 'Global' ?
I think this should raise a debugger warning, no ?

Code: Select all

EnableExplicit

Global myPoint.POINT ; myPoint as 'Global'

Procedure Dummy1()
  Shared myPoint ; This line should be removed - and it should raise a warning ! (?)
  myPoint\x = 111
  myPoint\y = 222
EndProcedure

Procedure Dummy2()
  Debug myPoint\x
  Debug myPoint\y
EndProcedure

Dummy1()
Dummy2()

Posted: Mon Dec 18, 2006 8:50 pm
by Fred
It's no use, but it's not an error as well..

Posted: Tue Dec 19, 2006 3:30 am
by Kaeru Gaman
months ago we discussed in the german forum, whether the implementation
of Shared is similar to the basic idea of Shared Variables or not.

since PureBasic has a MainCode, where you also declare Globals,
its not that strange that Shared variables are accessable in this Maincode, too.
and with this, its consistent, that it has to be Defined in the Maincode,
when EnableExplicit is active.

@flype
> what the use to 'Shared' a variable previously defined as 'Global' ?
the Variable is already Global, so it can be accessed in the Procedure.

if you try something like this:

Code: Select all

Global test.s
Define test.f
you'll receive an Error.

so, if you keep in mind, to preDefine every Shared Variable in the Maincode,
you will be informed if some name conflict appears.