为什么要用Variants类型?,你可以用指向指针的动态数组来做.
另一方向,根据变体类型在System单元中的定义,也可以看出,变体类型是不支持指针的.
TVarData = packed record
VType: TVarType;
case Integer of
0: (Reserved1: Word;
case Integer of
0: (Reserved2, Reserved3: Word;
case Integer of
varSmallInt: (VSmallInt: SmallInt);
varInteger: (VInteger: Integer);
varSingle: (VSingle: Single);
varDouble: (VDouble: Double);
varCurrency: (VCurrency: Currency);
varDate: (VDate: TDateTime);
varOleStr: (VOleStr: PWideChar);
varDispatch: (VDispatch: Pointer);
varError: (VError: LongWord);
varBoolean: (VBoolean: WordBool);
varUnknown: (VUnknown: Pointer);
varShortInt: (VShortInt: ShortInt);
varByte: (VByte: Byte);
varWord: (VWord: Word);
varLongWord: (VLongWord: LongWord);
varInt64: (VInt64: Int64);
varString: (VString: Pointer);
varAny: (VAny: Pointer);
varArray: (VArray: PVarArray);
varByRef: (VPointer: Pointer);
);
1: (VLongs: array[0..2] of LongInt);
);
2: (VWords: array [0..6] of Word);
3: (VBytes: array [0..13] of Byte);
{ Variant type codes (wtypes.h) }
varEmpty = $0000
{ vt_empty }
varNull = $0001
{ vt_null }
varSmallint = $0002
{ vt_i2 }
varInteger = $0003
{ vt_i4 }
varSingle = $0004
{ vt_r4 }
varDouble = $0005
{ vt_r8 }
varCurrency = $0006
{ vt_cy }
varDate = $0007
{ vt_date }
varOleStr = $0008
{ vt_bstr }
varDispatch = $0009
{ vt_dispatch }
varError = $000A
{ vt_error }
varBoolean = $000B
{ vt_bool }
varVariant = $000C
{ vt_variant }
varUnknown = $000D
{ vt_unknown }
//varDecimal = $000E
{ vt_decimal } {UNSUPPORTED}
{ undefined $0f } {UNSUPPORTED}
varShortInt = $0010
{ vt_i1 }
varByte = $0011
{ vt_ui1 }
varWord = $0012
{ vt_ui2 }
varLongWord = $0013
{ vt_ui4 }
varInt64 = $0014
{ vt_i8 }
//varWord64 = $0015
{ vt_ui8 } {UNSUPPORTED}
{ if adding new items, update Variants' varLast, BaseTypeMap and OpTypeMap }
varStrArg = $0048
{ vt_clsid }
varString = $0100
{ Pascal string
not OLE compatible }
varAny = $0101
{ Corba any }
varTypeMask = $0FFF;
varArray = $2000;
varByRef = $4000;
资料来源: Delphi5开发人员指南 第33页.
原句如下:
.....
注意 在上面的列表代码中你可能发现,Variant不能代表指针和类.
TVarData = packed record
VType: TVarType;
case Integer of
0: (Reserved1: Word;
case Integer of
0: (Reserved2, Reserved3: Word;
case Integer of
varSmallInt: (VSmallInt: SmallInt);
varInteger: (VInteger: Integer);
varSingle: (VSingle: Single);
varDouble: (VDouble: Double);
varCurrency: (VCurrency: Currency);
varDate: (VDate: TDateTime);
varOleStr: (VOleStr: PWideChar);
varDispatch: (VDispatch: Pointer);
varError: (VError: LongWord);
varBoolean: (VBoolean: WordBool);
varUnknown: (VUnknown: Pointer);
varShortInt: (VShortInt: ShortInt);
varByte: (VByte: Byte);
varWord: (VWord: Word);
varLongWord: (VLongWord: LongWord);
varInt64: (VInt64: Int64);
varString: (VString: Pointer);
varAny: (VAny: Pointer);
varArray: (VArray: PVarArray);
varByRef: (VPointer: Pointer);
);
1: (VLongs: array[0..2] of LongInt);
);
2: (VWords: array [0..6] of Word);
3: (VBytes: array [0..13] of Byte);
{ Variant type codes (wtypes.h) }
varEmpty = $0000
{ vt_empty }
varNull = $0001
{ vt_null }
varSmallint = $0002
{ vt_i2 }
varInteger = $0003
{ vt_i4 }
varSingle = $0004
{ vt_r4 }
varDouble = $0005
{ vt_r8 }
varCurrency = $0006
{ vt_cy }
varDate = $0007
{ vt_date }
varOleStr = $0008
{ vt_bstr }
varDispatch = $0009
{ vt_dispatch }
varError = $000A
{ vt_error }
varBoolean = $000B
{ vt_bool }
varVariant = $000C
{ vt_variant }
varUnknown = $000D
{ vt_unknown }
//varDecimal = $000E
{ vt_decimal } {UNSUPPORTED}
{ undefined $0f } {UNSUPPORTED}
varShortInt = $0010
{ vt_i1 }
varByte = $0011
{ vt_ui1 }
varWord = $0012
{ vt_ui2 }
varLongWord = $0013
{ vt_ui4 }
varInt64 = $0014
{ vt_i8 }
//varWord64 = $0015
{ vt_ui8 } {UNSUPPORTED}
{ if adding new items, update Variants' varLast, BaseTypeMap and OpTypeMap }
varStrArg = $0048
{ vt_clsid }
varString = $0100
{ Pascal string
not OLE compatible }
varAny = $0101
{ Corba any }
varTypeMask = $0FFF;
varArray = $2000;
varByRef = $4000;