A simple function example:
begin
if not Assigned(FArray[AIndex]) then
FArray[AIndex] := CreateItem(AIndex);
Result := FArray[AIndex];
end;
where FArray is a dynamic array of objects. It seems that Assigned() doesn't work well here. For example, when Length(FArray) = 1, Assigned(FArray[1]) = True, Assigned(FArray[198]) = True, and so on. Some indexes return true, some false.
I assume this just has to do with the nature of a dynamic array in the first place, so I'm wondering if there's a different way to use Assigned() in this case, or a different command. I know workarounds like checking something about that index's specific object, etc., but I'm mainly looking for a better understanding of Assigned() in this case and something directly related to it.
Thanks.
begin
if not Assigned(FArray[AIndex]) then
FArray[AIndex] := CreateItem(AIndex);
Result := FArray[AIndex];
end;
where FArray is a dynamic array of objects. It seems that Assigned() doesn't work well here. For example, when Length(FArray) = 1, Assigned(FArray[1]) = True, Assigned(FArray[198]) = True, and so on. Some indexes return true, some false.
I assume this just has to do with the nature of a dynamic array in the first place, so I'm wondering if there's a different way to use Assigned() in this case, or a different command. I know workarounds like checking something about that index's specific object, etc., but I'm mainly looking for a better understanding of Assigned() in this case and something directly related to it.
Thanks.