怎么获取记录类型变量的类型信息(200分)

  • 主题发起人 主题发起人 you_99
  • 开始时间 开始时间
Y

you_99

Unregistered / Unconfirmed
GUEST, unregistred user!
type
A = record
str: string;
int: integer;
end;
var
aA: A;
请问我如何获取变量aA的类型信息?
 
aA.XXX
他自己就会显示出什么类型
 
aA.classname ?
 
我记得有个函数会返回变量类型 Type什么的
 
对不起,可能我没有说清楚.我是指在运行期获取该变量的类型信息即RTTI (runtime type information),
 
我想起来了,如果是类你用 xxx.classname,如果是变量你可以用VarType()
 
大不了,你在记录类型中加多一个成员作为标识
 
我的要求是写一个函数能够分析出所有记录类型(已知的和未知的)变量的结构
 
Returns the type code of a specified Variant.

Unit

System

Category

Variant support routines

function VarType(const V: Variant): Integer;

Description

VarType returns the type code of the given Variant. The resulting value is constructed from the following constants declared in the System unit.

const

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;

varStrArg = $0048;

varString = $0100;
varAny = $0101;
varTypeMask = $0FFF;
varArray = $2000;

varByRef = $4000;

The lower twelve bits of a Variant type code (the bits defined by the varTypeMask bit mask) define the type of the Variant. The varArray bit is set if the Variant is an array of the given type. The varByRef bit is set if the Variant is a reference to a value of the given type as opposed to an actual value.

The following table describes the meaning of each of the Variant type codes.

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 IUnknown interface pointer).
varByte A Byte
varStrArg COM-compatible string.
varString Reference to a dynamically allocated string. (not COM compatible)
varAny A CORBA Any value.

The value returned by VarType corresponds to the VType field of a TVarData record.

The type of a Variant can be changed using VarAsType or VarCast.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部