HomeClarion Live! UniversityScope of Variables in a Class, by sonic77 and Mark Goldberg
 
  • PDF

Scope of Variables in a Class, by sonic77 and Mark Goldberg

sonic77:

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.


!ABCIncludeFile(ctTaskDlg)
! ctTaskDialog.inc
PCWSTR                   EQUATE(LONG)
WORD                     EQUATE(USHORT)
TD_SHIELD_ICON           PCWSTR

Initializer          CLASS, MODULE('ctTaskDialog.clw'), LINK('ctTaskDialog.clw')
Construct              PROCEDURE
                     END

! ctTaskDialog.clw
  MEMBER
  INCLUDE('ctTaskDialog.inc')
  MAP
    MAKEINTRESOURCE(WORD wLow, WORD wHi=0), ULONG
  END

MAKEINTRESOURCE PROCEDURE (WORD wLow, WORD wHi=0) !, ULONG
  CODE
  IF Band(wHI, 08000h) THEN ! If (wHi And &H8000&Wink Then
    RETURN BOR(BOR(BAND(wHi, 07FFFh) * 010000h, BAND(wLow, 0FFFFh)), 080000000h) ! MAKELONG = (((wHi And &H7FFF&Wink * 65536) Or (wLow And &HFFFF&Wink) Or &H80000000
  ELSE
    RETURN BOR(BAND(wHi, 07FFFh) * 010000h, BAND(wLow, 0FFFFh)) ! MAKELONG = LOWORD(wLow) Or (&H10000 * LOWORD(wHi)) ! 'MAKELONG = ((wHi * 65535) + wLow)
  END

Initializer.Construct PROCEDURE
  CODE
  ! 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
  PROGRAM
INCLUDE('ctTaskDialog.inc'), ONCE
  MAP
  END
  CODE         
  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

Mark.Goldberg:

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

Mark.Goldberg: ((nod))
btw, change those hard coded hex contstants to equates to improve readability
Joomla Templates: from JoomlaShack