您的位置:首页 > 其它

获取变量数据类型的程序

2009-01-25 16:12 288 查看
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐