My understanding is that what you do array of Single the compiler effectively creates a type for it (hidden). So you have two different types, which are not compatible (even though they are defined the same).
Try creating a type:
type
TMySingleArray : array of Single;
And then use that instead (of array of Single) as the compiler will treat them being the same type (instead of two separate types with the same definition).
Please note: Been jumping between Delphi and other languages, so I may have gotten the syntax incorrect. Apologies if this is the case.
Yes, that seems to be the reason. I’ve seen this type declaration before in other people’s code, but not realised why it was required. Something new learned! Thank you. The type declaration I ended up using was: TScanBuffer = array of Single;
John, I was using Copy as shown. The issue was as Nick said - the compiler treats the arrays as different types if they were not derived from the same declaration.
If the parameter to the copy was converted into a pointer and the copy included a length (as the array may not end in a #00) then it would be independent of type and so there should be no type tests. But who knows, I may be wrong and a never (as far as possible) use pointers.
TArray<Single> does indeed work too. I’ll probably stick with the type declaration though as it also means there’s only one place to change it if the array data type needs to change later.
Copy that John/Paul suggested is way cleaner. Also CopyMemory is the WinAPI stub, Move which is the native Delphi method would be preferred for raw memory copying.
Something to note if you do have different definitions you can use TArray.Copy<> which does some checks before branching to either a low level mem copy for raw types or a safe copy for managed types:
const
CONST_ARRAY: array[5..10] of Single = (1, 2, 3, 4, 5, 6);
var
dest: array of Single;
begin
var dynArray: array of Single := [1, 2, 3, 4, 5, 6];
SetLength(dest, Length(dynArray));
TArray.Copy<Single>(dynArray, dest, Length(dynArray));
SetLength(dest, Length(CONST_ARRAY));
TArray.Copy<Single>(CONST_ARRAY, dest, Length(CONST_ARRAY));
var genArray: TArray<Single> := [1, 2, 3, 4, 5, 6];
SetLength(dest, Length(genArray));
TArray.Copy<Single>(genArray, dest, Length(genArray));