This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Pages: 1 - Last Post: 25 Jan 22, 20:01 Last Post By: RobM
RobM

Posts: 3,999
Registered: 4-Aug-2006
Version 17.1.5 broke current variable
Posted: 25 Jan 22, 17:45
 
  Click to reply to this thread Reply
Version 17 decodes
<pre>current</pre>
as a list of keys and values bound to the current object. From 17.1.5 you no longer get the key/value pairs but instead get something like
<pre>[Slide @ 750049004: 69]->[IndexVars @ 1773554974: 3]->[FolderVars @ 710258153: 23]->[Globals @ 1477797353: 57]</pre>


Solution, correct the code or do nothing and update the Developer docs to show something like
<%
vars = currentObject.getVars();
for (String name : vars.keySet()) {
     out.println(name + " = " + vars.get(name));
}
%>
ctwist

Posts: 443
Registered: 27-Sep-2003
Re: Version 17.1.5 broke current variable
Posted: 25 Jan 22, 18:55   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
The class type of "current" is "Scope".

You can get a list of keys and values like this:
out.print(current.getMap());
The behaviour of Scope changed in 17.1. I don't know whether or not this was intentional.
davidekholm

Posts: 3,624
Registered: 18-Oct-2002
Re: Version 17.1.5 broke current variable
Posted: 25 Jan 22, 19:15   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
If you wish to print all keys and values, call current.flatten().toString(); The Scope is like a Map, but also contains a reference to a parent Scope/Map, forming a chain. If you call current.getMap().toString(), then you're printing the keys and values of the innermost scope only.
davidekholm

Posts: 3,624
Registered: 18-Oct-2002
Re: Version 17.1.5 broke current variable
Posted: 25 Jan 22, 19:25   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
By the way, never rely on the formatting of things returned from toString() calls. That formatting is for human use / debugging use. I'll explain the formatting of Scope's toString for you:

If it reads like this: [Slide @ 750049004: 69]->[IndexVars @ 1773554974: 3]->[FolderVars @ 710258153: 23]->[Globals @ 1477797353: 57]

This is interpreted as one "Slide" scope containing 69 variables. Its parent is an "IndexVars" scope containing 3 variables. Its parent is a "FolderVars" scope containing 23 variables and its parent is the "Globals" scope containing 57 variables. The @ <number> indicates the equivalent of a memory location so you can tell various instances apart even if they contain the same data. If the same variable occurs in both an outer and inner scope, then you'll get the innermost one when querying the scope instance for it. The Scope mechanism is designed to mimic how variables in a computer language can occur in inner and outer scopes, where the inner scope "hides" the corresponding variables in the outer scope. See this pseudo code:
String name="David";
print name; // Prints David
{ // Local scope introduced here
  String name = "Anders";
  print name; // prints "Anders"
}
print name; // Prints David again


Edited by: JeffTucker on 25 Jan 2022, 14:00, to fix formatting
RobM

Posts: 3,999
Registered: 4-Aug-2006
Re: Version 17.1.5 broke current variable
Posted: 25 Jan 22, 19:32   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Updated the developers page to show new call method.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums