Scope of Variables in a Class, by sonic77 and Mark Goldberg
- Monday, 21 March 2011 14:39
- Last Updated on Tuesday, 30 November 1999 00:00
I've created a small test program that has a variable in a inc file, that's initialized from a class constructor. in the main program that variable does not hold the value that was set.
Initializer CLASS, MODULE('ctTaskDialog.clw'), LINK('ctTaskDialog.clw')
MAKEINTRESOURCE(WORD wLow, WORD wHi=0), ULONG
MAKEINTRESOURCE PROCEDURE (WORD wLow, WORD wHi=0) !, ULONG
IF Band(wHI, 08000h) THEN ! If (wHi And &H8000& Then
RETURN BOR(BOR(BAND(wHi, 07FFFh) * 010000h, BAND(wLow, 0FFFFh)), 080000000h) ! MAKELONG = (((wHi And &H7FFF& * 65536) Or (wLow And &HFFFF&) Or &H80000000
RETURN BOR(BAND(wHi, 07FFFh) * 010000h, BAND(wLow, 0FFFFh)) ! MAKELONG = LOWORD(wLow) Or (&H10000 * LOWORD(wHi)) ! 'MAKELONG = ((wHi * 65535) + wLow)
! Values are being set on program initialization but when the variables are read they do not have the specified value
TD_SHIELD_ICON = MAKEINTRESOURCE(-4)
[6:53:27 AM] sonic77: ! TaskDialogTest.clw
MESSAGE('TD_SHIELD_ICON value = ' & TD_SHIELD_ICON & '|Should be value = ' & 0FFFCh)
i hope someone can shed some light on this issue, in the debugger i see that the code was executed as expected
For grins, lets move TS_SHIELD_ICON inside of the Initializer Class
I don't know if this is the case, but you might be seeing two different variables, visible from different scopes.
It would be interesting to show the address(TS_SHIELD_ICON)
from the main program, and from inside of the class module.
when moved inside the class the value is correct
Mark.Goldberg: now you'll wanna rename Initializer
sonic77: inside the class and in the main program there is a different address
so, the inc defines TS_SHIELD_ICON as a variable in main and the inc included in the clw defines a TS_SHIELD_ICON scoped to the class file
btw, change those hard coded hex contstants to equates to improve readability