You have to use shared in all procedures, you use it.
You only need to use the keyword Shared in those procedures that need access to the var. Or, alternatively, define the var in the main scope and use
Shared in one or more procedures that need access. If you have 15 procedures, by no means do all procedures need the definition. That would mimic Global. One common use for it is if you have a procedure and you're calling something like EnumChildWindows() or such from it. You would use Shared to allow those two procs to know a particular variable, where none of the others know it or need to:
Code: Select all
Procedure four( )
Debug "four: "+Str(x) ; not shared here!
EndProcedure
Procedure three( )
Debug "three: "+Str(x) ; or here!
four()
EndProcedure
Procedure two()
Shared x
Debug "two: "+Str(x)
three()
EndProcedure
Procedure one()
Shared x
x=10
Debug "one: "+Str(x)
two()
EndProcedure
one()
As I hope is obvious by now, a
Shared variable must exist in a minimum of two places in your code to make any sense (and actually do something useful). If it exists in only one place, there is nobody to share with. This is what was wrong with the posted snippet.
The EnumChildWindows is a good example because the EnumProc can't return anything. You want to know something from it, you share a var in the caller and the EnumProc, then let EnumProc set it. The caller receives it because of Shared.
I hope this helps to clear it up for you, as Shared isn't bugged and is quite useful just as it is.
@ts-soft: I know you understand all this, I think your english let you down a bit on this one
