I have some functions which accepts an array of TObject as a var parameter, for example:
type
TObjectArray = array of TObject;
...
procedure DeleteAt(var AArray : TObjectArray; AIndex : integer);
begin
while(AIndex < Length(AArray) - 1) do
begin
AArray[AIndex] := AArray[AIndex + 1];
Inc(AIndex);
end;
SetLength(AArray, Length(AArray) - 1);
end;
For reusing the same functions, I'm casting several dynamic array of TObject's descendant classes to TObjectArray before passing them to my functions, for example:
var
Buttons : array of TButton;
begin
SetLength(Buttons, 1);
Buttons[0] := Button1;
//...
DeleteAt(TObjectArray(Buttons), 0);
end;
Is this a safe practice or it could cause some problem that I didn't considered?