如何判断Variant当前的类型,又如何读出它的值呢? (20分)

  • 主题发起人 主题发起人 microrain
  • 开始时间 开始时间
M

microrain

Unregistered / Unconfirmed
GUEST, unregistred user!
帮帮我呀,我将一个数据库的记录集传给了一个Variant变量,怎么再将每条记录从这个
Variant变量中读出来呀??

          ///|///  
        // .-.- //  
       ( .@.@ )
+-----------oOOo-----(_)-----oOOo----------+
|   网海茫茫,认识你是我的福份;    | 
|   网语缠绵,那是我们注定的缘份。   |  
|         microrain        |  
|         ★代码中国★ |
| webmaster@codechina.net |
|      http://www.codechina.net |
+------------------------------------------+
 
你用VarType来判断不就行了?
如下:
function VarType(const V: Variant): TVarType;

VarType Contents of variant

varEmpty The variant is Unassigned.
varNull The variant is Null.
varSmallint 16-bit signed integer (type Smallint).
varInteger 32-bit signed integer (type Integer).
varSingle Single-precision floating-point value (type Single).
varDouble Double-precision floating-point value (type Double).
varCurrency Currency floating-point value (type Currency).
varDate Date and time value (type TDateTime).
varOleStr Reference to a dynamically allocated UNICODE string.

varDispatch Reference to an Automation object (an IDispatch interface pointer).
varError Operating system error code.
varBoolean 16-bit boolean (type WordBool).
varVariant A variant.
varUnknown Reference to an unknown OLE object (an IInterface or IUnknown interface pointer).
varShortInt 8-bit signed integer (type ShortInt)
varByte A Byte
varWord unsigned 16-bit value (Word)
varLongWord unsigned 32-bit value (LongWord)
varInt64 64-bit signed integer (Int64)

varStrArg COM-compatible string.
varString Reference to a dynamically allocated string (not COM compatible).
varAny A CORBA Any value.
 
VarType( V: Variant ): Integer;
varEmpty $0000
varNull $0001
varSmallint $0002
varInteger $0003
varSingle $0004
varDouble $0005
varCurrency $0006
varDate $0007
varOleStr $0008
varDispatch $0009
varError $000A
varBoolean $000B
varVariant $000C
varUnknown $000D
varByte $0011
varString $0100
varTypeMask $0FFF
varArray $2000
varByRef $4000

For Example:
var
A: Variant;
B: Integer;
begin
A:= True;
B:= VarType(A)

MessageDlg( VarToStr(B), mtInformation, [mbOk], 0);
end;
 
读取可以用VarAsType(),VarToStr()函数!
 
判断这样就可以
a:variant
if a is varByte then//varByte指的是类型
 
后退
顶部