Page 1 of 1

Thread object accesibility

Posted: Mon Nov 09, 2015 3:58 pm
by bwolfsohn
In our xb2net application, i have a thread object.

i can refer to it in code

Code: Select all

x:=oThread:getvar("userid")
However, i can't figure out if it's possible to access this dynamically i.e.

Code: Select all

x:=[oThread:getvar("userid")]
? &x
is this possible ??

Re: Thread object accesibility

Posted: Tue Nov 10, 2015 1:30 am
by skiman
Hi Brian,

Maybe as follows?

Code: Select all

x:='{|o| o:getvar("userid")}'
bBlock := &(x)
? eval(bBlock,oThread)

Re: Thread object accesibility

Posted: Tue Nov 10, 2015 8:30 am
by rdonnay
The macro will work only if oThread is a private or public variable.

Re: Thread object accesibility

Posted: Tue Nov 10, 2015 8:52 am
by bwolfsohn
is it possible to only macro the var portion in some way ???

x:="userid"
? oThread:getvar(&x)

Re: Thread object accesibility

Posted: Tue Nov 10, 2015 9:13 am
by skiman
Brian,

Code: Select all

x:='userid'
bBlock := &('{|o| o:getvar("'+x+'")}')
? eval(bBlock,oThread)

Re: Thread object accesibility

Posted: Wed Nov 11, 2015 12:29 pm
by bwolfsohn
skiman wrote:Brian,

Code: Select all

x:='userid'
bBlock := &('{|o| o:getvar("'+x+'")}')
? eval(bBlock,oThread)

Chris,

this worked fine for oThread..

But, with no getvar for oSession:profile , i'm stuck again... :pray: :pray:

oSession and oSession:profile are both objects.. i ned to dynamically grab the value of a class var in profile...

Re: Thread object accesibility

Posted: Thu Nov 12, 2015 12:46 am
by skiman
Hi Brian,

Can you explain this? It should work without any problem.

Also the previous posted code can be optimized this way:

Code: Select all

bBlock := {|o,x| o:getvar(x)}
x:="userid"
? eval(bBlock,oThread,x)
For your oSession sample:

Code: Select all

bBlock := {|o,cVar,oProfile| oProfile:=o:profile, oProfile:getvar(cVar) }
x := 'userid'
cUserid := eval(bBlock,oSession,x)

Re: Thread object accesibility

Posted: Thu Nov 12, 2015 12:31 pm
by bwolfsohn
skiman wrote:Hi Brian,

Can you explain this? It should work without any problem.

Also the previous posted code can be optimized this way:

Code: Select all

bBlock := {|o,x| o:getvar(x)}
x:="userid"
? eval(bBlock,oThread,x)
For your oSession sample:

Code: Select all

bBlock := {|o,cVar,oProfile| oProfile:=o:profile, oProfile:getvar(cVar) }
x := 'userid'
cUserid := eval(bBlock,oSession,x)
Chris,
The oThread example works perfectly...
the oProfile example does not...
getvar is not a method in osession

it looks like i need to add an inline method getvar to my oSession class...

Re: Thread object accesibility

Posted: Thu Nov 12, 2015 6:39 pm
by Auge_Ohr
bwolfsohn wrote: The oThread example works perfectly...
the oProfile example does not...
getvar is not a method in osession
what about using oProfile:Cargo Slot ?

Re: Thread object accesibility

Posted: Fri Nov 13, 2015 1:07 am
by skiman
Hi Brian,

Just a wild guess:

Code: Select all

bBlock := {|o,cVar,oProfile| oProfile:=o:profile, oProfile:&(cVar) }
x := 'userid'
cUserid := eval(bBlock,oSession,x)