I have a procedure that expects an array of Tobject, and an array of some class and I can't get them to work together.
type
TtestRec = class
// some fields
end;
procedure LoadOne(var element : Tobject); begin end;
procedure LoadAll(var all : array of Tobject); begin end;
var testArray : array of TtestRec;
begin
// fill the array
LoadOne(testArray[0]); // no problem
LoadAll(testArray); // incompatible types: 'array of Tobject' and 'Dynamic array'
I would like to call LoadAll
with arrays of all kinds of classes. What should I change?
LoadAll(TArray<TObject>(testArray))
. – Andreas Rejbrand 2 days agoLoadOne
doesn't compile either. There's a reason why you can't do this. How is yourLoadOne
orLoadAll
function going to know how to instantiate the correct type? – David Heffernan 2 days agoTtestRec
is a descendant ofTObject
.TtestRec = class
means exactly the same thing asTtestRec = class(TObject)
. – Andreas Rejbrand 2 days ago