Hi,
This is a Delphi limitation, in Delphi the following code won't compile:
var
a: Array of byte;
b: Array of byte;
begin
a:=b;
Because even when they are both array of bytes, delphi creates a different and incompatible type every time you declare a new array of something.
This is why you can't do:
var
ColumnFormats: array of tColumnImportType;
This will create a new type definition that won't be compatible with the one in the method.
But, this restriction doesn't apply to generic arrays, and 2 "TArray<something>" are type compatible, while 2 "array of something" aren't.
In short, define ColumnFormats this way:
ColumnFormats: TArray<TColumnImportType>;
and it will compile (because it will be type compatible with the TArray<TColumnImportType> that is required)
Regards,
Adrian.
Ps: Remember that if you don't care about the ColumnImportType, you can set this parameter to nil, no need to define a variable with the array:
xls.Import (Stream, 0,0, #9, nil, TEncoding.Default, true);
Ps2: Also, if you want you can initialize the array "in place" without defining a variable:
xls.Import (Stream, 0,0, #9, TArray<TColumnImportType>.Create(TColumnImportType.Skip, TColumnImportType.General), TEncoding.Default, true);
But this is probably going to be less clear. It is probably a good idea to define the array on its own line.