I have a function in my application that needs to return an array. I have found in a couple of places how to do this by declaring the array type, e.g.
type
TStringArray = array of string;
And then declaring my function
function SomeFunction(SomeParam: Integer): TStringArray;
My problem is trying to set this up in a form that has both interface and implementation. How do I declare my type and have a function declaration with that type in the interface ?
TStringDynArray = array of string; TStringArray = array[0..(maxInt div sizeof(string))-1] of string;But there is no official convention about it.FileIOunit uses which is part of the XE RTL usesTStringDynArrayextensively. So I don't agree that it is not idiomatic. Especially if you want to return the array and loop over it using an enumerator this is very convenient (seeTDirectory.GetFilesfor an example).TStringListis even less idiomatic, beacause it violates the "creator is responsible for destruction" principlefor FileName in TDirectory.GetFiles do ...so much more elegant thanStrList := TStringList.Create; try TDirectory.GetFiles (StrList); for FileName in StrList do ... finally StrList.Free; end;Are there any disadvantages of the array approach? Otherwise there's no reason not to use it IMHO