如对一个变量,假设看不到其定义部分,如何知道它的类型

解决方案 »

  1.   

    Returns the type code of a specified variant.UnitVariantsCategoryVariant support routinesDelphi syntax:function VarType(const V: Variant): TVarType;C++ syntax:extern PACKAGE TVarType __fastcall VarType(const Variant &V);DescriptionVarType returns the type code of the given variant. The resulting value is either the type code for a custom Variant type, or it is constructed from the constants declared in the System unit.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 defined in the System unit:VarType Contents of variantvarEmpty The variant is Unassigned.
    varNull The variant is Null.
    varSmallint 16-bit signed integer (type Smallint in Delphi, short in C++ ).
    varInteger 32-bit signed integer (type Integer in Delphi, int in C++).
    varSingle Single-precision floating-point value (type Single in Delphi, float in C++).
    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 object (an IInterface or IUnknown interface pointer).
    varShortInt 8-bit signed integer (type ShortInt in Delphi or signed char in C++)
    varByte A Byte
    varWord unsigned 16-bit value (Word)varLongWord unsigned 32-bit value (type LongWord in Delphi or unsigned long in C++)
    varInt64 64-bit signed integer (Int64 in Delphi or __int64 in C++)
    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.
      

  2.   

    function VarType(const V: Variant): TVarType;
      

  3.   

    支持以上且有
    function VarType(const V: Variant): TVarType;
    begin
      Result := TVarData(V).VType;
    end;
    TVarData = packed record
        case Integer of
          0: (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: HRESULT);
                            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);
              );
          1: (RawData: array [0..3] of LongInt);
      end;
      

  4.   

    呵呵,如果这个变量是一个类的实例,可以用.ClassName
      

  5.   

    var
     s:word;  //定义不同的类型...
    begin
     ShowMessage(IntToStr(VarType(s)));
    end;显示出不同的数字,譬如string是256....有趣...
      

  6.   

    我是想做一个辅助工具,给定一个类的名称(包括自定义类),能自动解析出该类所有的属性和方法,其属性可以进一步解析出其所属类型的所有属性、方法,直到 TObject和简单数据类型,以树的形式列出来。
      现在的问题是:如何能枚举出一个类的所有属性和方法?