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.