Homepage › Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › Access Global variable
- This topic has 14 replies, 5 voices, and was last updated 14 years, 11 months ago by Dennis Pfeifer.
-
CreatorTopic
-
October 13, 2009 at 7:44 pm #51247Rick PritchettParticipant
Is there any way to access a global variable created by a proc in an xlate? -
CreatorTopic
-
AuthorReplies
-
-
October 13, 2009 at 7:50 pm #69345Jim KosloskeyParticipant
Rick,
Where do you want to reference it from?
email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.
-
October 13, 2009 at 7:54 pm #69346Rick PritchettParticipant
I want to create the global in a proc and access it in a copy command inside the xlate tool if possible. The proc is located in the pre-xlate.
-
October 13, 2009 at 8:59 pm #69347Jim KosloskeyParticipant
Rick,
I am not sure if that will work however, this should work:
In the pre_xlate proc place the data you want in the metadata USERDATA field (I use a keyed list but you can do whatever you want). Then get the value for the keyed list enty from the USERDATA metadata field of the message in the Xlate with an xltp type proc.
email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.
-
October 13, 2009 at 9:35 pm #69348Charlie BursellParticipant
Yes it will work since they run in the same interprter. You can access the variable by declarining it global in both places or giving it a namespace path like ::gvar.
I have done this on many occasions
-
October 13, 2009 at 10:14 pm #69349Jim KosloskeyParticipant
Charlie,
Thanks that is good to know. I have never had a need to do what Rick is trying but I have used the USERDATA when I wanted something I set in the inbound thread to be known in an outbound thread.
email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.
-
October 14, 2009 at 2:19 pm #69350Rick PritchettParticipant
thank guys ! One last thing do i need to null out the global once i am finished with it.
-
October 14, 2009 at 2:46 pm #69351Charlie BursellParticipant
Depends on what you mean by null out.
To set to empty string: set ::gvar “”
To destroy it: unset -nocomplain ::gvar
-
October 14, 2009 at 3:34 pm #69352Jim KosloskeyParticipant
Rick,
Do you want to reset with each message or after some event has occurred?
email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.
-
October 14, 2009 at 4:17 pm #69353Rick PritchettParticipant
after i use it in the xalte
-
October 17, 2009 at 11:32 pm #69354Charlie BursellParticipant
Regarding my answer to Jim Koslosky concerning the use of globals in the Xlate thread, I got this response from one of the developers:
FYI, this will not work in 5.8. The interp used in the xlate was hardcoded which killed things in threaded xlates so Tcl fragments in the xlate no longer run in the same interp as the pre/post Tps.
Therefore, for forward compatibility, you best choice to communicate would be as Jim suggested and use the USERDATA meta field of the message.[/quote]
-
October 19, 2009 at 12:52 pm #69355Russ RossParticipant
I was going to mention that using a global variable solution is riskier and less robust because it makes an assumption that creates a denpendancy that might not hold up over time.
Now that Charlie has already come up with such an example I’m willing to add my voice to this concern.
Here is a URL with a tanglible example to help show how to value the USERDATA metatadata in an xlate and retrieve the value in an outbound thread that is even in a different process.
<a href="http://clovertech.infor.com/viewtopic.php?t=1367&” class=”bbcode_url”>http://clovertech.infor.com/viewtopic.php?t=1367&Russ Ross
RussRoss318@gmail.com -
October 20, 2009 at 2:45 pm #69356Rick PritchettParticipant
Thanks guys!!
-
November 3, 2009 at 1:56 pm #69357Dennis PfeiferParticipant
An instance where I have used a global in the Xlate thread, was in using a global across multiple interfaces, but all in the same process. My specific example was tracking patients’ room and bed. I could have used a file on disk, or database, but instead, I used memory. Updates were written to disk (to support startup), but ‘reads’ came from the global which was shared across multiple ‘Xlates’ …. saved some disk I/O.
Dennis
-
November 5, 2009 at 1:34 pm #69358Dennis PfeiferParticipant
Oh, Ya, after reading another ‘thread’ .. I realized that we also do this for database connections…
If the connection exisits, we use the global… which is shared amoungst all Xlates in the same process.
Dennis
-
-
AuthorReplies
- The forum ‘Cloverleaf’ is closed to new topics and replies.