INSTANCE - need to declare data as a property inside of a class,thread

I just hit an oddity where INSTANCE(Var,ThreadNum) doesn’t work on some data
However declaring the data as a property of a class,thread does work.


I wanted to be able to get the Window Title of the topmost window on each thread

I already had a system where I tracked the most recent window that had focus (other than the frame)
I do this by calling a method inside of every accept loop with the current window
that method set’s a &Window property - (protected by reader/writer sync objects)
(yes eventually I’ll create a system that relies on OpenWindowHook & CloseWindowHook, but I’m getting off of the subject)

So… I figured I could just add a &Window,THREAD variable and set that in my method
then later use INSTANCE( TheVar, ThreadNum ) but it didn’t work.

I wrote a testbed,
I tried working with other data types, namely &STRING,THREAD and QUEUE,THREAD
I did get success with the QUEUE
but could not get the &STRING to work.
Note: tested in C11.0.13224

I copied the example program out of the ClarionHelp.chm, and it worked as advertised.
Hmm, WTF am I missing?
Looking at the example closely, I eventually decided to try moving my data into properties of a class,thread which is what we see in the help file example,
and suddenly INSTANCE was working for my &String too.

ctWinVar          CLASS,TYPE 
Win                 &Window 
                  END 
Thd:CurrentWindow ctWinVar,THREAD  
!Thd:CurrentWindow &Window,THREAD  ! <<<- didn't work with INSTANCE

!==============================================
ctCommonGlobal.SET_CurrWindow          PROCEDURE(*WINDOW xaWindow)
  CODE
  SELF.CurrentWindowRW.Set(xaWindow) !<-- my original system
  Thd:CurrentWindow.Win &= xaWindow 

!==============================================
ctCommonGlobal.Get_CurrWindowOnThread  PROCEDURE(SIGNED xThreadNum)!,*WINDOW
RetWindow &Window 
oWinVar   &ctWinVar
  CODE 
     oWinVar &= INSTANCE( Thd:CurrentWindow, xThreadNum )
  IF oWinVar &= NULL 
        RetWindow &= NULL 
  ELSE  RetWindow &= oWinVar.Win 
  END
  RETURN RetWindow
2 Likes

Clarion works correctly here. Remember that reference variables are dereferencing automatically in all contexts with one exception if a reference variable is a destination (left side) in a reference assignment statement.

So, if you have declaration

RefW &WINDOW, THREAD

, the code

inst = INSTANCE (RefW, threadno)

if equivalent to

inst = INSTANCE (value assigned to RefW in the current thread, threadno)