How to programmaticly remove a class of variables

Stimulsoft Reports.Flex discussion
Locked
brianj774
Posts: 177
Joined: Tue Jan 11, 2011 7:15 am
Location: Minnesota

How to programmaticly remove a class of variables

Post 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?
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

How to programmaticly remove a class of variables

Post 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.
brianj774
Posts: 177
Joined: Tue Jan 11, 2011 7:15 am
Location: Minnesota

How to programmaticly remove a class of variables

Post 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);
				}
			}
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

How to programmaticly remove a class of variables

Post 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.
brianj774
Posts: 177
Joined: Tue Jan 11, 2011 7:15 am
Location: Minnesota

How to programmaticly remove a class of variables

Post 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
Andrew
Posts: 4108
Joined: Fri Jun 09, 2006 3:58 am

How to programmaticly remove a class of variables

Post 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.
Locked