Re: Difference between listbox...exchange and listbox...move?

Posted by Lee p12462 on February 17, 2009

In Reply to Re: Difference between listbox...exchange and listbox...move? posted by Jenny, DelphiLand Team on February 05, 2009

: : I tried both of these and they "seem" to do the same thing (swap items corresponding to the 2 indexes passed). Is there a subtle difference (I'm sure there is) that I'm missing?
: : With a ListBox with 4 unique items, I'm trying:
: : Form1.ListBox.Items.exchange(1,2); or
: : Form1.ListBox.Items.move(1,2);
: : This swaps the 2nd and 3rd items in the listbox.

: In your example, both statements perform exactly the same task, but that's purely "by accident" ;)
: Starting from items such as A, B, C, D, both Items.Exchange(1,2) and Items.Move(1,2) give us:
: A, C, B, D
: But with different item numbers, again starting from A, B, C, D we see after Items.Exchange(1,3):
: A, D, C, B
: Compare this with starting from A, B, C, D and Items.Move(1,3):
: A, C, D, B

Thanks Jenny,

I understood most of your results but was confused by your results on the Exchange(1,3) ...

[Lee, You're right. Sorry, I made a typing error in the order of the items.
I've corrected it in this thread, otherwise it would be too confusing for our other readers...]

...so I wrote a "quickie" program to do the operations that you suggested.


What you pointed out was that the MOVE removes the first item specified (#1) and causes all subsequent values to move up in the table. Then the removed first item (1) gets inserted at the position indicated by the second item specified (on the move statement) which was 3.

Thanks for the help!

Related articles

       

Follow Ups