このエラーは、V[1] がバリアント配列であることを示しています。実際にあることを確認できますVarIsArray(V[1])
それを表示するのに役立ついくつかの方法があります。
TPsVarDataType = (
vdtDefault, // varEmpty
vdtNull,
vdtSmallint,
vdtInteger,
vdtSingle,
vdtDouble,
vdtCurrency,
vdtDate,
vdtOleStr, // varOleStr, varString, varUString
vdtDispatch,
vdtError,
vdtBoolean,
vdtVariant,
vdtUnknown,
vdtDecimal,
vdtUndefined,
vdtShortint,
vdtByte,
vdtWord,
vdtLongWord,
vdtInt64,
{$IFDEF D2009_OR_LATER}
vdtUInt64,
{$ENDIF}
vdtUnsupported
{Usupported types
VT_UI8 = 21,
VT_INT = 22,
VT_UINT = 23,
VT_VOID = 24,
VT_HRESULT = 25,
VT_PTR = 26,
VT_SAFEARRAY = 27,
VT_CARRAY = 28,
VT_USERDEFINED = 29,
VT_LPSTR = 30,
VT_LPWSTR = 31,
VT_RECORD = 36,
VT_FILETIME = 64,
VT_BLOB = 65,
VT_STREAM = 66,
VT_STORAGE = 67,
VT_STREAMED_OBJECT = 68,
VT_STORED_OBJECT = 69,
VT_BLOB_OBJECT = 70,
VT_CF = 71,
VT_CLSID = 72,
VT_VERSIONED_STREAM = 73,
VT_BSTR_BLOB = 0xfff,
VT_VECTOR = 0x1000,
VT_ARRAY = 0x2000,
VT_BYREF = 0x4000,
VT_RESERVED = 0x8000,
VT_ILLEGAL = 0xffff,
VT_ILLEGALMASKED = 0xfff,
VT_TYPEMASK = 0xfff
}
);
const
SPsVarDataTypes: array [TPsVarDataType] of string = (
'Default',
'Null',
'Smallint',
'Integer',
'Single',
'Double',
'Currency',
'Date',
'OleStr',
'Dispatch',
'Error',
'Boolean',
'Variant',
'Unknown',
'Decimal',
'Undefined',
'Shortint',
'Byte',
'Word',
'LongWord',
'Int64',
{$IFDEF D2009_OR_LATER}
'UInt64',
{$ENDIF}
'Unsupported'
);
const
SPsVarDataTypes: array [TPsVarDataType] of string = (
'Default',
'Null',
'Smallint',
'Integer',
'Single',
'Double',
'Currency',
'Date',
'OleStr',
'Dispatch',
'Error',
'Boolean',
'Variant',
'Unknown',
'Decimal',
'Undefined',
'Shortint',
'Byte',
'Word',
'LongWord',
'Int64',
{$IFDEF D2009_OR_LATER}
'UInt64',
{$ENDIF}
'Unsupported'
);
SPsVarArray = 'Array of %s';
SPsVarByRef = '%s (Reference)';
function VariantToStr(V: Variant; IncludeType: Boolean = False): string;
begin
if VarIsArray(V) then
Result := VarArrayToStr(V)
else
case VarType(V) of
varError:
Result := Format('Error($%x)', [TVarData(v).VError]);
varNull:
Result := '#NULL';
varEmpty:
Result := '#EMPTY';
varDate:
Result := FormatDateTime(ShortDateFormat + ' ' + LongTimeFormat + '.zzz', V)
else
Result := VarToStr(V);
end;
if IncludeType then
Result := Format('%s{%s}', [Result, VarTypeToString(VarType(V))]);
end;
function VarArrayToStr(v: Variant; Delimiter: Char = #0; LineDelimiter: Char =
#13): string;
var
i,j,d: Integer;
line: string;
begin
if VarIsArray(v) then
begin
if Delimiter = #0 then
Delimiter := ListSeparator;
if LineDelimiter = #0 then
LineDelimiter := ListSeparator;
d := VarArrayDimCount(v);
// The elements
case d of
1:
begin
Result := '';
for i := VarArrayLowBound(v,1) to VarArrayHighBound(v,1) do
Result := Result + VariantToStr(v[i]) + Delimiter;
if Length(Result) > 0 then
SetLength(Result, Length(Result)-1);
end;
2:
begin
Result := '';
if (VarArrayLowBound(v,1) <= VarArrayHighBound(v,1)) and
(VarArrayLowBound(v,2) <= VarArrayHighBound(v,2)) then
begin
for i := VarArrayLowBound(v,1) to VarArrayHighBound(v,1) do
begin
line := '';
for j := VarArrayLowBound(v,2) to VarArrayHighBound(v,2) do
line := line + VariantToStr(v[i,j]) + Delimiter;
if Length(Result) > 0 then
SetLength(line, Length(line)-1);
Result := Result + LineDelimiter + Format('[%s]', [line]);
end;
end;
end // 2
else
Result := 'Array Dim=' + IntToStr(d);
end;
Result := Format('[%s]', [Result]);
end
else
Result := VarToStr(v);
end;
function VarTypeToString(varType: Integer): string;
var
T: TPsVarDataType;
begin
if varType = varString then
Result := 'string'
else
begin
T := VarTypeToPsVarDataType(varType);
if T = vdtUnSupported then
Result := IntToStr(varType and varTypeMask)
else
Result := SPsVarDataTypes[T];
end;
if (varType and varArray) <> 0 then
Result := Format(SPsVarArray,[Result]);
if (varType and varByRef) <> 0 then
Result := Format(SPsVarByRef,[Result]);
end;
function VarTypeToPsVarDataType(Value: Word): TPsVarDataType;
var
v: Word;
begin
debugEnter('VarTypeToPsVarDataType');
v := Value and varTypeMask;
debugInt('Value', v);
if v < Word(vdtUnsupported) then
result := TPsVarDataType(v)
else if v = varString then
result := vdtOleStr
{$IFDEF D2009_OR_LATER}
else if v = varUString then
result := vdtOleStr
{$ENDIF}
else
result := vdtUnsupported;
debugLeave;
end;
function PsVarDataTypeToVarType(Value: TPsVarDataType; IsArray: Boolean =
False): Word;
begin
if Value = vdtUnsupported then
Result := varEmpty
else
begin
Result := Word(Value);
if IsArray then
Result := Result or varArray;
end;
end;
UPDATE 2012-09-20: 文字列定数を見逃したようです。追加した。UPDATE 2012-11-02: TPsVarDataType, VarTypeToPsVarDataType() & VarTypeToPsVarDataType();