Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Local scoop wish
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00720623
Message ID:
00721007
Views:
12
I don't beleive you got me right, my wish was to have a new sys() function to changed the default behavior of VFP from creating all undeclared variable as LOCAL to the function declaring it:

Current behavior:
ox = CreateObject("Test")
=ox.Test1()
Define Class Test As Session

	Function Test1
		x = 1
		? x
		? This.Test2()
	EndFunc

	Function Test2
		Return x && x is private so no error here
	EndFunc
	
EndDefine
New Sys() Option
ox = CreateObject("Test")
=ox.Test1()

Define Class Test As Session
	
	Protected Function Init()
		=Sys(9999, 1)  && New sys function
	EndFunc
	
	Function Test1
		x = 1
		? x
		? This.Test2()
	EndFunc

	Function Test2
		Return x && x an error here, x is local to test1()
	EndFunc
	

EndDefine
>>VFP supports block scoop, the block is the whole function.
>
>This is not what I would call block scope. It is function scope.
>
>>I would not disagree having block scoop to IF - Case - For - Etc... Statements, but this would really break a lot of existing code.
>
>Not if you introduce a new syntax, like braces or an VB-like "Option scope" at the top of the code block.
>
>Ex.:
>Without code block:
FOR I = 1 TO 10
>   LOCAL N && N has procedure scope although it was declared within a block.
>   N = I
>ENDFOR
>
>W = 10 ^ N    && N is still visible outside the block it is declared in
>With code block:
FOR I = 1 TO 10
>   {
>      LOCAL N && N has block scope
>      N = I
>   }
>ENDFOR
>
>W = 10 ^ N    && Error: N is not visible outside the block it is declared in
>
>>I don't agrree a new Sys() function would make it harder the code to read, i would put the SYS() call in the INIT of my MTDLL's base class and then forget about it.
>
>What if I want to write a new class that will be used by different applications having different scope definition? I would have to go through the gymnastic of saving the current setting, change it to what I need and restore it back. This will clutter my code.
>
>This may also break existing code in your global classes that your application call.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform