System.Rtti.TValue

提供: RAD Studio API Documentation
移動先: 案内検索

Delphi

  TValue = record
  private class var
    FEmpty: TValue;
  private
    class constructor Create;
    function GetIsEmpty: Boolean;
    function GetTypeInfo: PTypeInfo; inline;
    function GetTypeKind: TTypeKind;
    function GetTypeDataProp: PTypeData;
    function GetDataSize: Integer;
{$HINTS OFF}
    constructor Create(ATypeInfo: PTypeInfo);
{$HINTS ON}
    class function GetEmpty: TValue; static;
    procedure Get<T>(out Result: T);
  public
    class operator Implicit(const Value: string): TValue;
    class operator Implicit(Value: Integer): TValue;
    class operator Implicit(Value: Cardinal): TValue;
    class operator Implicit(Value: Single): TValue;
    class operator Implicit(Value: Double): TValue;
    class operator Implicit(Value: Extended): TValue;
    class operator Implicit(Value: Currency): TValue;
    class operator Implicit(Value: Int64): TValue;
    class operator Implicit(Value: UInt64): TValue;
    class operator Implicit(Value: TObject): TValue;
    class operator Implicit(Value: TClass): TValue;
    class operator Implicit(Value: Boolean): TValue;
    class operator Implicit(const VarRec: TVarRec): TValue; inline;
    class function FromVariant(const Value: Variant): TValue; static;
    class function From<T>(const Value: T): TValue; inline; static;
    class function FromOrdinal(ATypeInfo: PTypeInfo; AValue: Int64): TValue; static;
    class function FromArray(ArrayTypeInfo: PTypeInfo; const Values: array of TValue): TValue; static;
    class function FromVarRec(const VarRec: TVarRec): TValue; static;
    property Kind: TTypeKind read GetTypeKind;
    property TypeInfo: PTypeInfo read GetTypeInfo;
    property TypeData: PTypeData read GetTypeDataProp;
    property IsEmpty: Boolean read GetIsEmpty;
    function IsObject: Boolean;
    function IsObjectInstance: Boolean;
    function AsObject: TObject;
    function IsInstanceOf(AClass: TClass): Boolean;
    function IsClass: Boolean; inline;
    function AsClass: TClass; inline;
    function IsOrdinal: Boolean;
    function AsOrdinal: Int64;
    function TryAsOrdinal(out AResult: Int64): Boolean;
    function IsType<T>(const EmptyAsAnyType: Boolean = True): Boolean; overload; inline;
    function IsType(ATypeInfo: PTypeInfo; const EmptyAsAnyType: Boolean = True): Boolean; overload;
    function AsType<T>(const EmptyAsAnyType: Boolean = True): T;
    function TryAsType<T>(out AResult: T; const EmptyAsAnyType: Boolean = True): Boolean;
    function Cast<T>(const EmptyAsAnyType: Boolean = True): TValue; overload;
    function Cast(ATypeInfo: PTypeInfo; const EmptyAsAnyType: Boolean = True): TValue; overload;
    function TryCast(ATypeInfo: PTypeInfo; out AResult: TValue; const EmptyAsAnyType: Boolean = True): Boolean;
    function AsInteger: Integer;
    function AsBoolean: Boolean;
    function AsExtended: Extended;
    function AsInt64: Int64;
    function AsUInt64: UInt64;
    function AsInterface: IInterface;
    function AsString: string;
    function AsVariant: Variant;
    function AsCurrency: Currency;
    function IsArray: Boolean;
    function CastToVarRec: TValue;
    function AsVarRec: TVarRec;
    function GetArrayLength: Integer;
    function GetArrayElement(Index: Integer): TValue;
    procedure SetArrayElement(Index: Integer; const AValue: TValue);
    class procedure Make(ABuffer: Pointer; ATypeInfo: PTypeInfo; var Result: TValue); overload; static;
    class procedure Make(AValue: NativeInt; ATypeInfo: PTypeInfo; var Result: TValue); overload; static;
    class procedure Make<T>(const Value: T; var Result: TValue); overload; static; inline;
    class procedure MakeWithoutCopy(ABuffer: Pointer; ATypeInfo: PTypeInfo; var Result: TValue; IsMoved: Boolean = False); overload; static;
    property DataSize: Integer read GetDataSize;
    procedure ExtractRawData(ABuffer: Pointer);
    procedure ExtractRawDataNoCopy(ABuffer: Pointer);
    function GetReferenceToRawData: Pointer;
    function GetReferenceToRawArrayElement(Index: Integer): Pointer;
    class property Empty: TValue read GetEmpty;
    function ToString: string;
  private
    FTypeInfo: PTypeInfo;
    FValueData: IValueData;
    case Integer of
      0: (FAsUByte: Byte);
      1: (FAsUWord: Word);
      2: (FAsULong: Cardinal);
      3: (FAsObject: Pointer);
      4: (FAsClass: TClass);
      5: (FAsSByte: ShortInt);
      6: (FAsSWord: SmallInt);
      7: (FAsSLong: Integer);
      8: (FAsSingle: Single);
      9: (FAsDouble: Double);
      10: (FAsExtended: Extended);
      11: (FAsComp: Comp);
      12: (FAsCurr: Currency);
      13: (FAsUInt64: UInt64);
      14: (FAsSInt64: Int64);
      15: (FAsMethod: TMethod);
      16: (FAsPointer: Pointer);
  end;

C++

struct __declspec(delphirecord) TValue
{
private:
    static TValue FEmpty;
private:
private:
    bool __fastcall GetIsEmpty();
    System::Typinfo::PTypeInfo __fastcall GetTypeInfo();
    System::TTypeKind __fastcall GetTypeKind();
    System::Typinfo::PTypeData __fastcall GetTypeDataProp();
    int __fastcall GetDataSize();
protected:
    __fastcall TValue(System::Typinfo::PTypeInfo ATypeInfo);
private:
    static TValue __fastcall GetEmpty();
    template<typename T> void __fastcall Get(/* out */ T &Result);
public:
    static TValue __fastcall _op_Implicit(const System::UnicodeString Value);
    static TValue __fastcall _op_Implicit(int Value);
    static TValue __fastcall _op_Implicit(unsigned Value);
    static TValue __fastcall _op_Implicit(float Value);
    static TValue __fastcall _op_Implicit(double Value);
    static TValue __fastcall _op_Implicit(System::Extended Value);
    static TValue __fastcall _op_Implicit(System::Currency Value);
    static TValue __fastcall _op_Implicit(__int64 Value);
    static TValue __fastcall _op_Implicit(unsigned __int64 Value);
    static TValue __fastcall _op_Implicit(System::TObject* Value);
    static TValue __fastcall _op_Implicit(System::TClass Value);
    static TValue __fastcall _op_Implicit(bool Value);
    static TValue __fastcall _op_Implicit(const System::TVarRec &VarRec);
    static TValue __fastcall FromVariant(const System::Variant &Value);
    template<typename T> static TValue __fastcall From(const T Value);
    static TValue __fastcall FromOrdinal(System::Typinfo::PTypeInfo ATypeInfo, __int64 AValue);
    static TValue __fastcall FromArray(System::Typinfo::PTypeInfo ArrayTypeInfo, const TValue *Values, const int Values_High);
    static TValue __fastcall FromVarRec(const System::TVarRec &VarRec);
    __property System::TTypeKind Kind = {read=GetTypeKind};
    __property System::Typinfo::PTypeInfo TypeInfo = {read=GetTypeInfo};
    __property System::Typinfo::PTypeData TypeData = {read=GetTypeDataProp};
    __property bool IsEmpty = {read=GetIsEmpty};
    bool __fastcall IsObject();
    bool __fastcall IsObjectInstance();
    System::TObject* __fastcall AsObject();
    bool __fastcall IsInstanceOf(System::TClass AClass);
    bool __fastcall IsClass();
    System::TClass __fastcall AsClass();
    bool __fastcall IsOrdinal();
    __int64 __fastcall AsOrdinal();
    bool __fastcall TryAsOrdinal(/* out */ __int64 &AResult);
    template<typename T> bool __fastcall IsType(const bool EmptyAsAnyType = true)/* overload */;
    bool __fastcall IsType(System::Typinfo::PTypeInfo ATypeInfo, const bool EmptyAsAnyType = true)/* overload */;
    template<typename T> T __fastcall AsType(const bool EmptyAsAnyType = true);
    template<typename T> bool __fastcall TryAsType(/* out */ T &AResult, const bool EmptyAsAnyType = true);
    template<typename T> TValue __fastcall Cast(const bool EmptyAsAnyType = true)/* overload */;
    TValue __fastcall Cast(System::Typinfo::PTypeInfo ATypeInfo, const bool EmptyAsAnyType = true)/* overload */;
    bool __fastcall TryCast(System::Typinfo::PTypeInfo ATypeInfo, /* out */ TValue &AResult, const bool EmptyAsAnyType = true);
    int __fastcall AsInteger();
    bool __fastcall AsBoolean();
    System::Extended __fastcall AsExtended();
    __int64 __fastcall AsInt64();
    unsigned __int64 __fastcall AsUInt64();
    System::_di_IInterface __fastcall AsInterface();
    System::UnicodeString __fastcall AsString();
    System::Variant __fastcall AsVariant();
    System::Currency __fastcall AsCurrency();
    bool __fastcall IsArray();
    TValue __fastcall CastToVarRec();
    System::TVarRec __fastcall AsVarRec();
    int __fastcall GetArrayLength();
    TValue __fastcall GetArrayElement(int Index);
    void __fastcall SetArrayElement(int Index, const TValue &AValue);
    static void __fastcall Make(void * ABuffer, System::Typinfo::PTypeInfo ATypeInfo, TValue &Result)/* overload */;
    static void __fastcall Make(NativeInt AValue, System::Typinfo::PTypeInfo ATypeInfo, TValue &Result)/* overload */;
    template<typename T> static void __fastcall Make(const T Value, TValue &Result)/* overload */;
    static void __fastcall MakeWithoutCopy(void * ABuffer, System::Typinfo::PTypeInfo ATypeInfo, TValue &Result, bool IsMoved = false)/* overload */;
    __property int DataSize = {read=GetDataSize};
    void __fastcall ExtractRawData(void * ABuffer);
    void __fastcall ExtractRawDataNoCopy(void * ABuffer);
    void * __fastcall GetReferenceToRawData();
    void * __fastcall GetReferenceToRawArrayElement(int Index);
    /* static */ __property TValue Empty = {read=GetEmpty};
    System::UnicodeString __fastcall ToString();
private:
    System::Typinfo::TTypeInfo *FTypeInfo;
    _di_IValueData FValueData;
public:
    TValue() {}
    TValue& operator =(const System::UnicodeString Value) { *this = TValue::_op_Implicit(Value); return *this; }
    TValue& operator =(int Value) { *this = TValue::_op_Implicit(Value); return *this; }
    TValue& operator =(unsigned Value) { *this = TValue::_op_Implicit(Value); return *this; }
    TValue& operator =(float Value) { *this = TValue::_op_Implicit(Value); return *this; }
    TValue& operator =(double Value) { *this = TValue::_op_Implicit(Value); return *this; }
    TValue& operator =(System::Extended Value) { *this = TValue::_op_Implicit(Value); return *this; }
    TValue& operator =(System::Currency Value) { *this = TValue::_op_Implicit(Value); return *this; }
    TValue& operator =(__int64 Value) { *this = TValue::_op_Implicit(Value); return *this; }
    TValue& operator =(unsigned __int64 Value) { *this = TValue::_op_Implicit(Value); return *this; }
    TValue& operator =(System::TObject* Value) { *this = TValue::_op_Implicit(Value); return *this; }
    TValue& operator =(System::TClass Value) { *this = TValue::_op_Implicit(Value); return *this; }
    TValue& operator =(bool Value) { *this = TValue::_op_Implicit(Value); return *this; }
    TValue& operator =(const System::TVarRec &VarRec) { *this = TValue::_op_Implicit(VarRec); return *this; }
private:
    union
    {
        struct
        {
            void *FAsPointer;
        };
        struct
        {
            System::TMethod FAsMethod;
        };
        struct
        {
            __int64 FAsSInt64;
        };
        struct
        {
            unsigned __int64 FAsUInt64;
        };
        struct
        {
            System::CurrencyBase FAsCurr;
        };
        struct
        {
            System::CompBase FAsComp;
        };
        struct
        {
            System::Extended FAsExtended;
        };
        struct
        {
            double FAsDouble;
        };
        struct
        {
            float FAsSingle;
        };
        struct
        {
            int FAsSLong;
        };
        struct
        {
            short FAsSWord;
        };
        struct
        {
            System::Int8 FAsSByte;
        };
        struct
        {
            System::TClass FAsClass;
        };
        struct
        {
            void *FAsObject;
        };
        struct
        {
            unsigned FAsULong;
        };
        struct
        {
            System::Word FAsUWord;
        };
        struct
        {
            System::Byte FAsUByte;
        };
    };
};

プロパティ

種類 可視性 ソース ユニット
record
struct
public
System.Rtti.pas
System.Rtti.hpp
System.Rtti System.Rtti

説明

バリアント型の軽量版を表します。

TValue は、さまざまな種類のデータ型を格納できるデータ構造です。TValue は、Rtti ユニットでフィールドやメソッド パラメータにアクセスしやすくするために使用されます。

関連項目