I wish I had blogged about this a lot sooner, as then far less people would use var aFoo: array of TFoo
as method parameters for results that are just out
parameters and could be a function result.
You cannot have array of TFoo
as function result, but you can have TArray<TFoo>
. The former would be an open array, the latter is a proper array type.
I see many people use var aFoo: array of TFoo
with all sorts of SetLength
calls before calling and inside a method where a function returning a TArray<TFoo>
would be far more appropriate, both in the sense of readability and maintainability.
–jeroen