Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Delphi Misc > How to move one...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 8 Topic 6023 of 6154
Post > Topic >>

How to move one element of Dynamic Array of Objects

by TeChNoInSiDe <tomatinhum@[EMAIL PROTECTED] > Mar 26, 2008 at 01:07 AM

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=3Dpt-BR&lnk=3Dgst

The real problem is those methods aren=B4t working for array of objects.

For example:

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D

var

TestArray: Array of TAdvGlowButton;

begin

//Clone components

TestArray[0] :=3D TAdvGlowButton component; //component cloned from
original button
TestArray[1] :=3D TAdvGlowButton component; //component cloned from
original button
TestArray[2] :=3D 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 :=3D 2 to High(TestArray) do
begin

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

end;

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D

The above code seems to be working correctly. The problem is when I
try to make the same thing with multi-dimensional arrays like this:

var

TestArray : Array of Array of TPanel;

begin

//clone components

TestArray[0][0] :=3D TPanel cloned component;
TestArray[0][1] :=3D TPanel cloned component;
TestArray[0][2] :=3D TPanel cloned component;
TestArray[1][0] :=3D TPanel cloned component;
TestArray[1][1] :=3D TPanel cloned component;
TestArray[1][2] :=3D TPanel cloned component;
TestArray[1][3] :=3D TPanel cloned component;
TestArray[1][4] :=3D TPanel cloned component;
TestArray[2][0] :=3D TPanel cloned component;

//Delete components from index 1

for i :=3D 0 to High(TestArray[1]) do FreeAndNil(TestArray[1][i]);

//Copy all elements from index 2 to index 1

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

      //Reset and resize main index with size of next index

      SetLength(TestArray[(i - 1)], 0);
      SetLength(TestArray[(i - 1)], Length(TestArray[i]));

    //Move data

    for j :=3D Low(TestArray[i]) to High(TestArray[i]) do
    begin

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

    end;

end;

This code will either generate delayed runtime access violations or
when the main application is closed it generates access violation
errors or invalid pointer operations.

Any tips?

Thank you in advance for any help.
 




 8 Posts in Topic:
How to move one element of Dynamic Array of Objects
TeChNoInSiDe <tomatinh  2008-03-26 01:07:49 
Re: How to move one element of Dynamic Array of Objects
"Maarten Wiltink&quo  2008-03-26 10:29:38 
Re: How to move one element of Dynamic Array of Objects
"Rudy Velthuis"  2008-03-26 12:16:49 
Re: How to move one element of Dynamic Array of Objects
Rob Kennedy <me3@[EMAI  2008-03-26 08:34:59 
Re: How to move one element of Dynamic Array of Objects
Hans-Peter Diettrich <  2008-03-26 16:23:34 
Re: How to move one element of Dynamic Array of Objects
"Rudy Velthuis"  2008-03-26 19:18:44 
Re: How to move one element of Dynamic Array of Objects
"Rudy Velthuis"  2008-03-26 19:23:03 
Re: How to move one element of Dynamic Array of Objects
TeChNoInSiDe <tomatinh  2008-03-31 15:10:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 3:19:14 CDT 2008.