I'm calling my own procedure clear() when I want to use a (generic) objectlist again.
procedure TMain.ClearAll;
var index : integer;
rij : TExpedRij;
begin
for index := fBlad.ExpeditieRijen.Count - 1 downto 0 do
begin
rij := fBlad.ExpeditieRijen[index];
rij.Free;
end;
fBlad.ExpeditieRijen.Clear;
end;
You have to clean up all inserted objects. Then I call property clear to set the index to 0.
First time goes well. Second time creates a sigdev.
But why? Cleaning up all the objects and set the index to 0 is very logical.
This is the code in FPC:
procedure TFPSList.Clear;
begin
if Assigned(FList) then
begin
SetCount(0);
SetCapacity(0);
end;
end;
Very straight line. But why a sigdev. For testing I put the line 'fBlad.ExpeditieRijen.Clear;' before the for loop. no sigdev, but the for loop will not executed at all.
procedure TMain.ClearAll;
var index : integer;
rij : TExpedRij;
begin
fBlad.ExpeditieRijen.Clear;
for index := fBlad.ExpeditieRijen.Count - 1 downto 0 do
begin
rij := fBlad.ExpeditieRijen[index];
rij.Free;
end;
end;
People always told my to clean up you own objects.
Does property clear clears all object automatically?
By the way function clear is calling a procedure twice.
procedure TFPSList.SetCount(NewCount: Integer);
begin
if (NewCount < 0) or (NewCount > MaxListSize) then
Error(SListCountError, NewCount);
if NewCount > FCapacity then
SetCapacity(NewCount);
if NewCount > FCount then
FillByte(InternalItems[FCount]^, (NewCount-FCount) * FItemSize, 0)
else if NewCount < FCount then
Deref(NewCount, FCount-1);
FCount := NewCount;
end;