Re: How to move one element of Dynamic Array of Objects
- From: Hans-Peter Diettrich <DrDiettrich1@xxxxxxx>
- Date: Wed, 26 Mar 2008 16:23:34 +0100
TeChNoInSiDe wrote:
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;
Your code migth work with fixed arrays:
TestArray : Array[0..2][0..4] of TPanel;
With dynamic arrays, you must initialize all subarrays:
SetLength(TestArray, n);
for i := 0 to n-1 do
SetLength(TestArray[i], m);
System.Move(TestArray[i][j], TestArray[(i - 1)][j], SizeOf(TestArray)
* (Length(TestArray) - (VIv_i - 1) - 1));
You shouldn't do this, because it can affect the reference counting of the subarrays.
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.
The FreeAndNil(TestArray[1]) most probably will cause an AV, because arrays are not TObjects. Only do
TestArray[i] := Nil;
or assign it another array.
You can delete reference counted array elements in an tricky way (see TStringList.Delete), but I'd recommend to move the arrays in an regular way:
for i := ...
TestArray[i] := TestArray[i+1];
Finally set the last (now unused) array element to Nil.
DoDi
.
- Follow-Ups:
- 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: Rudy Velthuis
- Re: How to move one element of Dynamic Array of Objects
- References:
- How to move one element of Dynamic Array of Objects
- From: TeChNoInSiDe
- How to move one element of Dynamic Array of Objects
- Prev by Date: Re: How to move one element of Dynamic Array of Objects
- Next by Date: Re: install delphi 4 and 6 safely on same computer
- Previous by thread: Re: How to move one element of Dynamic Array of Objects
- Next by thread: Re: How to move one element of Dynamic Array of Objects
- Index(es):
Relevant Pages
|