How to move one element of Dynamic Array of Objects
- From: TeChNoInSiDe <tomatinhum@xxxxxxxxx>
- Date: Wed, 26 Mar 2008 01:07:49 -0700 (PDT)
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));
end;
===================================================
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] := TPanel cloned component;
TestArray[0][1] := TPanel cloned component;
TestArray[0][2] := TPanel cloned component;
TestArray[1][0] := TPanel cloned component;
TestArray[1][1] := TPanel cloned component;
TestArray[1][2] := TPanel cloned component;
TestArray[1][3] := TPanel cloned component;
TestArray[1][4] := TPanel cloned component;
TestArray[2][0] := TPanel cloned component;
//Delete components from index 1
for i := 0 to High(TestArray[1]) do FreeAndNil(TestArray[1][i]);
//Copy all elements from index 2 to index 1
for i := 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 := 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.
.
- Follow-Ups:
- Re: How to move one element of Dynamic Array of Objects
- From: Hans-Peter Diettrich
- Re: How to move one element of Dynamic Array of Objects
- From: Rob Kennedy
- Re: How to move one element of Dynamic Array of Objects
- From: Rudy Velthuis
- Re: How to move one element of Dynamic Array of Objects
- From: Maarten Wiltink
- Re: How to move one element of Dynamic Array of Objects
- Prev by Date: Re: install delphi 4 and 6 safely on same computer
- Next by Date: Re: How to move one element of Dynamic Array of Objects
- Previous by thread: install delphi 4 and 6 safely on same computer
- Next by thread: Re: How to move one element of Dynamic Array of Objects
- Index(es):