By default, an array inside a Variant is stored as (a pointer to) a COM SAFEARRAY:
https://docs.microsoft.com/en-us/archive/msdn-magazine/2017/march/introducing-the-safearray-data-structure
https://docs.microsoft.com/en-us/windows/win32/api/oaidl/ns-oaidl-safearray
Which is completely different than a Delphi-style dynamic array. The two are not compatible with each other. The only way to store a Delphi-style dynamic array AS-A dynamic array in a Variant is to use a custom Variant type:
https://docwiki.embarcadero.com/RADStudio/en/Defining_Custom_Variants
That being said, Delphi 10.2 and later are more strict about NOT letting you assign a raw Pointer to a dynamic array, as you are trying to do:
So, you would have to type-cast the raw Pointer in order to get the old Delphi 6 behavior, eg:
type
TDoubleArray = array of double;
var
Value: Variant; //this variable is assigned to a dynamic array somewhere in the code
...
procedure DoSomething;
var
rv: TDoubleArray;
begin
rv := TDoubleArray(TVarData(Value).VArray.Data); // note, no @ used here. Why would you want to assign a PPointer to a dynamic array???
...
end;
But, it never made sense to me why anyone would ever want to do this, since this makes the dynamic array point at something that is not a valid dynamic array, and can't be accessed as a dynamic array. The structure of a SAFEARRAY and a dynamic array are completely different.
In any case, to safely access the raw data of a SAFEARRAY, you MUST use the SafeArrayAccessData() function, which Delphi's RTL has wrapped in the VarArrayLock() function, eg:
var
Value: Variant; //this variable is assigned to a dynamic array somewhere in the code
...
procedure DoSomething;
var
rv: PDouble;
begin
rv := PDouble(VarArrayLock(Value));
try
// use rv as needed...
finally
VarArrayUnlock(Value);
end;
end;