Re: How to move one element of Dynamic Array of Objects



TeChNoInSiDe wrote:

Hi!

I read a topic about moving array indexes here:


http://groups.google.com.br/group/comp.lang.pascal.delphi.misc/browse_thread/thread/b2a8c7320a060999/8de55d44c9827f7d?hl=pt-BR&lnk=gst

The real problem is those methods aren´t working for array of objects.

For example:

===================================================

var

TestArray: Array of TAdvGlowButton;

begin

//Clone components

TestArray[0] := TAdvGlowButton component; //component cloned from
original button
TestArray[1] := TAdvGlowButton component; //component cloned from
original button
TestArray[2] := TAdvGlowButton component; //component cloned from
original button

//Delete component at index 1

FreeAndNil(TestArray[1]);

//Move component at index 2 to index 1

for i := 2 to High(TestArray) do
begin

System.Move(TestArray[i], TestArray[(i - 1)], SizeOf(TestArray) *
(Length(TestArray) - (i - 1) - 1));


Why are you doing that in a loop? You only want to do ONE big move, or
move each entry one by one. But not both at the same time.
--
Rudy Velthuis http://rvelthuis.de

"We don't make mistakes, we just have happy little accidents."
-- Bob Ross, "The Joy of Painting"
.


Quantcast