Page 1 of 1
[PB520B14] DeclareModul and Define (Done, not Bug)
Posted: Thu Aug 29, 2013 8:14 pm
by mk-soft
Invalid starting value within modules
Code: Select all
DeclareModule myTest
Define var1.i = 1
;Global var1.i = 1
Declare foo()
EndDeclareModule
Module myTest
Procedure foo()
Protected iTemp
iTemp = var1
Debug "foo(): " + iTemp
EndProcedure
EndModule
; Test
UseModule myTest
foo()
Debug "Debug: " + var1
UnuseModule myTest
myTest::foo()
Debug "Debug: " + myTest::var1
Re: [PB520B14] DeclareModul and Define
Posted: Thu Aug 29, 2013 9:08 pm
by Little John
mk-soft wrote:Invalid starting value within modules
What output do you get?
Exactly which part of the output did you not expect?
Re: [PB520B14] DeclareModul and Define
Posted: Thu Aug 29, 2013 9:17 pm
by luis
Code: Select all
foo(): 0
Debug: 1
foo(): 0
Debug: 1
What's the problem ?
Re: [PB520B14] DeclareModul and Define
Posted: Thu Aug 29, 2013 9:27 pm
by mk-soft
Different values for "var1". Internal maintenance of the procedure foo is the value of the varible zero. Outside of Procedure, the starting value of the variable.
Re: [PB520B14] DeclareModul and Define
Posted: Thu Aug 29, 2013 9:31 pm
by luis
Uhm... are you saying the problem is var1 is ZERO inside the proc and 1 outside ?
Define is not global, so it's normal that inside the proc var1 is zero.
But define is local to the module's scope, so if you print the value of var1 outside of the proc it's 1.
Try to put an EnableExplicit inside declaremodule.
Re: [PB520B14] DeclareModul and Define
Posted: Thu Aug 29, 2013 9:33 pm
by Little John
mk-soft wrote:Different values for "var1". Internal maintenance of the procedure foo is the value of the varible zero. Outside of Procedure, the starting value of the variable.

I'm not able to understand this text.
I'm getting the same output as Luis, and don't see any problem as well.
Maybe using
EnableExplicit will help you to understand what's going on.
Re: [PB520B14] DeclareModul and Define
Posted: Thu Aug 29, 2013 9:35 pm
by mk-soft
Just found myself. Sorry, not a bug.
Define in modules somehow make no sense
Re: [PB520B14] DeclareModul and Define
Posted: Thu Aug 29, 2013 9:39 pm
by luis
mk-soft wrote:
Define in modules somehow make no sense
It does exactly what it does outside the modules.
A local variable, not a global one and not one visible inside a procedure unless you use Shared.
Code: Select all
Define var1.i = 1
Procedure foo()
Protected iTemp
iTemp = var1
Debug "foo(): " + iTemp
EndProcedure
foo()
Debug "Debug: " + var1