Variable Scope in a Table

bhalpin
Member Posts: 309
Hi. This has me baffled.
I have a form with SourceTable T
The form calls T's function (call it T.F1) to pass values to the table.
The call looks like F1(value1,value2,value3, etc.)
T.F1 sets globals in the table to the passed values and returns.
The form calls another function (call it 'T.F2') in the table.
In T.F2, the globals set before are all there.
T.F2 then calls another function in the same table (T.F3)
In T.F3 all the globals are empty/zero.
I know there has to be a good explanation for this ... :-k
Can anyone shed some light on this?
Thanks!
I have a form with SourceTable T
The form calls T's function (call it T.F1) to pass values to the table.
The call looks like F1(value1,value2,value3, etc.)
T.F1 sets globals in the table to the passed values and returns.
The form calls another function (call it 'T.F2') in the table.
In T.F2, the globals set before are all there.
T.F2 then calls another function in the same table (T.F3)
In T.F3 all the globals are empty/zero.
I know there has to be a good explanation for this ... :-k
Can anyone shed some light on this?
Thanks!
0
Comments
-
0
-
It's probably because F3 is looking at a different variable. I've seen many times that local and global variables have the same names, and scope gets confused sometimes.0
-
Hi. Thanks all.
By the way Denster - there is no collision between local and global variables.
I tried modifying the code as follows:
Form calls Table function T.F1 with several parameters.
T.F1 sets globals in the table to the passed values.
T.F1 then calls function T.F2 to verify the variables all have values.
In T.F2 the global values all have the expected values.
T.F1 then calls T.F3 to do some work using the global variables.
In T.F3 the variables are all empty.
The behaviour is weird - especially since this is all happening in one function call to the table that spawns other function calls (presumably) withing the same table/record.
But, this is NAV, so things can get "interesting" ... and in this case it looks like the scope/persistence of globals in a record is somewhat "undefined".
Thanks all, I've already worked around it (by holding my nose and pulling the code into the form.)
B0 -
this one can help, too!it happened to me...
http://www.mibuso.com/forum/viewtopic.php?f=23&t=427600 -
DenSter wrote:It's probably because F3 is looking at a different variable. I've seen many times that local and global variables have the same names, and scope gets confused sometimes.
not confusion,it's looking as when a local variable has same name to global variable then the local variable overright to global in his scope(you can not use global variable in local scope it hide to global).0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions