获取变量数据类型的程序

 

Delphi syntax:

 

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 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)

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

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.

 

-------------------------------------------------------------------------------------------------------------------

 

unit UntVarType;

 

interface

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls;

 

type

  TForm1 = class(TForm)

    Button1: TButton;

    Label1: TLabel;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.dfm}

{

   获取变量的数据类型

}

Function getVarType(value: variant):string;

begin

  case varType(value) of

      varEmpty     : Result :='Unassigned';

      varNull      : Result := 'Null';

      varSmallint : Result := 'Smallint';

      varInteger : Result := 'integer';

      varSingle   : Result := 'Single';

      varDouble   : Result := 'double';

      varCurrency : Result := 'Currency';

      varDate      : Result := 'TDateTime';

 

      varOleStr   : Result := 'OleStr';

      varDispatch : Result := 'Dispatch';

      varError   : Result := 'error';

      varBoolean   : Result := 'boolean';

      varVariant   : Result := 'variant';

      varUnknown   : Result := 'unknown';

      varShortInt  : Result := 'ShortInt';

      varByte      : Result := 'Byte';

      varWord      : Result := 'Word';

 

      varLongWord  : Result := 'LongWord';

      varInt64     : Result := 'integer';

      varStrArg    : Result := 'strArg';

      varString    : Result := 'string';

      varAny       : Result := 'Any';

  end;

end;

 

{

    测试

}

procedure TForm1.Button1Click(Sender: TObject);

var

  i: integer;

  w: word;

  b: Boolean;

  E: Tdatetime;

begin

  showmessage(getVarType(i));  {Integer}

  showmessage(getVarType(w));  {word}

  showmessage(getVarType(b));  {Boolean}

  showmessage(getVarType(E));  {Tdatetime}

end;

 

end.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值