获取变量数据类型的程序
2009-01-16 00:11
351 查看
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.
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.
相关文章推荐
- 获取变量数据类型的程序
- 黑马程序员_Java基础_02常量、变量、数据类型、运算符、语句、程序执行过程
- PowerShell中使用GetType获取变量数据类型
- C语言如何获取某个数据类型或变量的大小?
- JS魔法堂:函数重载 之 获取变量的数据类型
- Transact-SQL 示例 - 如何获取一个变量的数据类型
- 第一章 变量 数据类型 常用获取元素的方式
- Transact-SQL 示例 - 如何获取一个变量的数据类型
- C/C++学习之C提高----C程序数组排序、数据类型(大小,别名,封装)、变量、程序的内存四区模型(栈,堆,全局,代码区)
- java获取变量数据类型
- python获取变量的数据类型
- JAVA菜鸟入门篇-第一个java程序、变量和数据类型(三)
- c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程
- java基础--JDK安装、环境变量配置、工具开发第一个程序、数据类型、运算符
- 随堂笔记第一天:环境变量配置,代码的三种注释方法,第一个程序,基本数据类型------1
- java小知识点-获取变量得数据类型
- javascrip获取变量的数据类型
- 我也要学C语言-第三章:C程序的数据,数据类型还有变量
- python获取变量的数据类型
- 获取一个变量的数据类型