Collection base and use of too many items...

S

Sonnich Jensen

Hi

I found a problem in out SW, which basically is:

for 0 to something (right now 15) do:
whatever.Groups[i / 16].Items.Add();
whatever.Groups[i / 16].Items[i % 16].Text = "whatever";
whatever.Groups[i / 16].Items[i % 16].Caption = "whatever";

Now, how odd it may sound, it might try to fill more than I have
The items are a collection base, where it works as:

public _our_component_class Items
{
get { return items; }
}
and

public _our_component_class this[int index]
{
get { return (_our_component_class)List[index]; } // crashes here if we have less items than asked for

set { List[index] = value; }
}

Now, I can add automatically, but is there a better way to simply ignore remaining "inputs"
I know there are prober solutions, but rewriting all the software from anyone in this company it really not an option... so a hack here seems to be the best
I my current config there are 12 items in a group, so when it asks for 12-15 it will fail.


WBR
Sonnich
 
A

Arne Vajhøj

I found a problem in out SW, which basically is:

for 0 to something (right now 15) do:
whatever.Groups[i / 16].Items.Add();
whatever.Groups[i / 16].Items[i % 16].Text = "whatever";
whatever.Groups[i / 16].Items[i % 16].Caption = "whatever";

Now, how odd it may sound, it might try to fill more than I have
The items are a collection base, where it works as:

public _our_component_class Items
{
get { return items; }
}
and

public _our_component_class this[int index]
{
get { return (_our_component_class)List[index]; } // crashes here if we have less items than asked for

set { List[index] = value; }
}

Now, I can add automatically, but is there a better way to simply ignore remaining "inputs"
I know there are prober solutions, but rewriting all the software from anyone in this company it really not an option... so a hack here seems to be the best
I my current config there are 12 items in a group, so when it asks for 12-15 it will fail.

As far as I can then both the easiest and most correct solution is
to fix the for loop, so that it does not iterate over more than it
should.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top