獲取變數資料型別的程式

2021-04-24 15:02:46 字數 3679 閱讀 4549

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 inte***ce pointer).

varerror                      operating system error code.

varboolean                 16-bit boolean (type wordbool).

varvariant                   a variant.

varunknown               reference to an unknown object (an iinte***ce or iunknown inte***ce                                    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;

inte***ce

uses

windows, messages, sysutils, variants, classes, graphics, controls, forms,

dialogs, stdctrls;

type

tform1 = class(tform)

button1: tbutton;

label1: tlabel;

procedure button1click(sender: tobject);

private

public

end;

varform1: tform1;

implementation

獲取變數的資料型別

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

vari: integer;

w: word;

b: boolean;

e: tdatetime;

begin

showmessage(getvartype(i));  

showmessage(getvartype(w));  

showmessage(getvartype(b));  

showmessage(getvartype(e));  

end;

end.

獲取變數資料型別

獲取變數資料型別 1 獲取檢測變數的資料型別 typeof可用來獲取檢測變數的資料型別 var num 10 console.log typeof num number var str abc console.log typeof str string var flag true console.l...

JS學習之獲取變數資料型別

doctype html utf 8 獲取變數資料型別 title var num 109,str1 pink flag true console.log typeof num console.log typeof str1 console.log typeof flag console.log t...

變數的資料型別

希望在這一點上,你會說,嘿,等一下,我不應該用浮點值做 的比較!然後你可以修改它以更適當的前進。從長遠來看,這會節省你很多時間。傳統的匈牙利命名法真正的缺點是對各種型別的化合物的字首的數量可以變得混亂。維基百科提供了乙個恰當的例子 a crszkvc30lastnamecol 乙個恆定的參考函式的引...