Page 1 of 1
How to programmaticly remove a class of variables
Posted: Tue May 10, 2011 6:10 pm
by brianj774
I have a report with some variables built in, and each execution of the report dynamically pushes other variables onto the report.
But I'm finding that I end up with multiple copies of the same variable, which causes some other problems, so, what I was hoping to do was to , after loading the report, identify the 'params' variable catagory, and delete it (and then re add the variables in the very next code block)
I'm not having any luck figuring out how to do this, however.
StiVariable itself doesn't seem to have the ability to remove itself from the collection, and I'm drawing a blank on how to get it to work. Can you explain how I might remove only SOME variables from the collection?
How to programmaticly remove a class of variables
Posted: Wed May 11, 2011 1:33 am
by Vladimir
Hello,
To remove a variable you can use the following code:
Code: Select all
var variable: StiVariable = report.dictionary.variables.getByName("Variable1");
report.dictionary.variables.remove(variable);
Thank you.
How to programmaticly remove a class of variables
Posted: Wed May 11, 2011 7:59 am
by brianj774
Thank you, thats what I needed.
For future reference, since I didn't know the variables ahead of time, I had to do it like this :
Code: Select all
var variable: StiVariable;
// clear the 'stored' variables...
var i:int = report.dictionary.variables.length;
for(i = i - 1; i >= 0; i--){
variable = report.dictionary.variables[i];
if(variable.category == "params") {
trace("removing " + variable.name);
report.dictionary.variables.remove(variable);
}
}
How to programmaticly remove a class of variables
Posted: Wed May 11, 2011 8:27 am
by Vladimir
Hello,
Using your code, not all variables of the category may be removed. You can use the following code:
Code: Select all
var variable: StiVariable;
var i: int = 0;
while (i < report.dictionary.variables.length)
{
variable = report.dictionary.variables[i];
if (variable.category == "params")
{
trace("removing " + variable.name);
report.dictionary.variables.remove(variable);
}
else i++;
}
Thank you.
How to programmaticly remove a class of variables
Posted: Wed May 11, 2011 2:51 pm
by brianj774
Hmm..I found it completely opposite. When I looped through the collection FORWARDS, I only was removing about half of the items, but, when I start at the last one, and test BACKWARDS, that worked fine.
I found that when going forward, if item 1 got removed, item 2 would become index 1, then, we'd test index 2, and the new item at index 1 would never be tested. Attacking in reverse solves this issue.
But, looking at your sample again, it appears that it would work just as well as mine, only advancing the pointer on an unsuccessful match.
Unless I'm missing something. Please let me know...I"ll be listening
How to programmaticly remove a class of variables
Posted: Thu May 12, 2011 3:05 pm
by Andrew
Hello,
Sorry for the misunderstanding. We have mistakenly looked at that the collection is taken from the first item. Your algorithm should also work correctly.
Thank you.