为什么v:=VarArrayCreate([0,8], varString);会出错?Delphi6

时间:2022-10-21 12:25:23
var v:variant;
begin
  v:=VarArrayCreate([0,8], varString); 
end;
//改为varInteger,varVariant都不会出错. varString为什么不行?
请指教,thank

6 个解决方案

#1


改为:
v:=VarArrayCreate([0,8], varolestr); 

#2


Creates a Variant array. 

Unit

System

Category

Variant support routines

function VarArrayCreate(const Bounds: array of Integer; VarType: Integer): Variant;

Description

VarArrayCreate creates a Variant array with the bounds given by Bounds and the element type given by VarType. 

The Bounds parameter must contain an even number of values, where each pair of values specifies the upper and lower bounds of one dimension of the array. 

The element type of the array, given by the VarType parameter, must be one of the TVarData type codes, and cannot include the varArray or varByRef bits. The element type cannot be varString. To create a Variant array of strings use the varOleStr type code. If the element type is varVariant, the elements of the array are themselves Variants and can in turn contain Variant arrays.

Note: Variant arrays with an element type of varByte are the preferred method of passing binary data between OLE Automation controllers and servers. Such arrays are subject to no translation of their data, and can be efficiently accessed using the VarArrayLock and VarArrayUnlock routines.

#3


var
  V: variant;
begin
  if VarTypeIsValidArrayType(varString) then
    V := VarArrayCreate([0, 8], varString);
end;

#4


VarTypeIsValidArrayType()//返回是否是有效的变态数组类型

#5


ok,thank,买单了

#6


使用

var v:variant;
begin
  v:=VarArrayCreate([0,8], vtString); 
                           ^^^^^^^^^
end;

在Delphi中   varString   = $0100; { Pascal string; not OLE compatible }

#1


改为:
v:=VarArrayCreate([0,8], varolestr); 

#2


Creates a Variant array. 

Unit

System

Category

Variant support routines

function VarArrayCreate(const Bounds: array of Integer; VarType: Integer): Variant;

Description

VarArrayCreate creates a Variant array with the bounds given by Bounds and the element type given by VarType. 

The Bounds parameter must contain an even number of values, where each pair of values specifies the upper and lower bounds of one dimension of the array. 

The element type of the array, given by the VarType parameter, must be one of the TVarData type codes, and cannot include the varArray or varByRef bits. The element type cannot be varString. To create a Variant array of strings use the varOleStr type code. If the element type is varVariant, the elements of the array are themselves Variants and can in turn contain Variant arrays.

Note: Variant arrays with an element type of varByte are the preferred method of passing binary data between OLE Automation controllers and servers. Such arrays are subject to no translation of their data, and can be efficiently accessed using the VarArrayLock and VarArrayUnlock routines.

#3


var
  V: variant;
begin
  if VarTypeIsValidArrayType(varString) then
    V := VarArrayCreate([0, 8], varString);
end;

#4


VarTypeIsValidArrayType()//返回是否是有效的变态数组类型

#5


ok,thank,买单了

#6


使用

var v:variant;
begin
  v:=VarArrayCreate([0,8], vtString); 
                           ^^^^^^^^^
end;

在Delphi中   varString   = $0100; { Pascal string; not OLE compatible }