Hi, I've got a problem I don't know how to solve, I have a 3 dimensional array, (say, cols,rows, depths?)
For each col/row the number of depths varies. I'm trying to delete from the array a whole row using a function deletex which deletes an element from a one dimensional array.
So, say I want to delete the third row from the array, first I delete all the depth elements from the second row of all the cols, this is successful.
then I "try" to delete the third element from all the cols , this is where I get a SIGSEGV fault. Any ideas how to do this, or alternate strategies? I did think of just using a one dimensional array, but, as depth varies, indexing would be a nightmare.
Best regards
Albert
type
TdoubleArray = array of double;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
procedure DeleteX(var A: tdoublearray; const Index: Cardinal);
end;
var
Form1: TForm1;
x:array of array of array of double;
//x:tintarray;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
i, k :byte;
begin
// delete elements in first position of third dimension of the first, second and third cols; third row
deletex(tdoublearray(x[0, 2]), 0);
deletex(tdoublearray(x[1, 2]), 0);
deletex(tdoublearray(x[2, 2]), 0);
// delete elements in second position of third dimension of the first, second and third cols; third row
deletex(tdoublearray(x[0, 2]), 1);
deletex(tdoublearray(x[1, 2]), 1);
deletex(tdoublearray(x[2, 2]), 1);
// now delete third row from first, second and third cols,
deletex(tdoublearray(x[0]), 2);
deletex(tdoublearray(x[1]), 2); // gives SIGSEGV error here
deletex(tdoublearray(x[2]), 2);
end;
procedure tform1.DeleteX(var A: Tdoublearray; const Index: Cardinal);
var
ALength: Cardinal;
TailElements: Cardinal;
begin
ALength := Length(A);
Assert(ALength > 0);
Assert(Index < ALength);
Finalize(A[Index]);
TailElements := ALength - Index;
if TailElements > 0 then
Move(A[Index + 1], A[Index], SizeOf(double)* TailElements); //
Initialize(A[ALength - 1]);
SetLength(A, ALength - 1);
end;
procedure TForm1.FormShow(Sender: TObject);
var
i,k:byte;
begin
setlength(x, 3, 10, 2); // three dimensional array, three cols, 10 rows, 2 depths?
for k:= 0 to 2 do // fill with something
for i := 0 to 9 do begin
x[k,i,0]:= i*(k+1);
x[k,i,1]:= i*2*(k+1);
end;
end;
end.