DELPHI中记录型动态数组删除,从中间删除一条记录,如果是一维的记录型,如ARRAY OF T1,则成功,如果是二维,则失败.
TYPE
T1=RECORD
YEAR:integer;
month:integer;
text:string;
end;
T2=record
mydate: array of T1;
end;
//如果是一维,L1,L2是TListbox,成功
procedure TForm1.Button3Click(Sender: TObject);
var
bb:array of t1;
i:integer;
begin
SetLength(bb,8);
for i:=low(bb) to high(bb) do
bb[i].YEAR:=i;
L1.Clear;
for i:=low(bb) to high(bb) do
l1.Items.Add(inttostr(bb[i].YEAR));
i:=1; //删除位置
Move(bb[i + 1], bb[i], (high(bb) - i) * SizeOf(t1));
SetLength(bb, length(bb) - 1);
L2.Clear;
for i:=low(bb) to high(bb) do
l2.Items.Add(inttostr(bb[i].YEAR));
end;
//如果是二维,失败,不能从中间删除
procedure TForm1.Button4Click(Sender: TObject);
var
bb:array of t2;
i,j:integer;
begin
SetLength(bb,5);
for i:=low(bb) to high(bb) do
begin
setlength(bb[i].mydate,4);
for j:=0 to 3 do
bb[i].mydate[j].YEAR:=i*100+j;
end;
L1.Clear;
for i:=low(bb) to high(bb) do
for j:=low(bb[i].mydate) to high(bb[i].mydate) do
l1.Items.Add(inttostr(bb[i].mydate[j].YEAR));
i:=2;
setlength(bb[i].mydate,0);
Move(bb[i + 1], bb[i], (high(bb) - i) * SizeOf(t2)); //还是有问题
SetLength(bb, length(bb) - 1);
L2.Clear;
for i:=low(bb) to high(bb) do
for j:=low(bb[i].mydate) to high(bb[i].mydate) do
l2.Items.Add(inttostr(bb[i].mydate[j].YEAR));
end;