Forum in READ ONLY mode! All questions and discussions on Discord official server, invite link: https://discord.gg/VxsGzJ7

How to determine Type of Variables on Fly[Pascal]

Ask for help
Post Reply
Crome696
Novice
Novice
Posts: 67
Joined: 04.03.2012 18:57
Location: Germany
Contact:

How to determine Type of Variables on Fly[Pascal]

Post by Crome696 »

Hello Community,
i checked different Manuals\References now but did not found the right function to get this working.
Think about you have the Datatype Variante ( Could be String or Integer or Double or whatever) and you want to use specific operations depending on Datatype.

In C# you can ask like

Code: Select all

if ( Variable is String )
and getting true or false as result.

Anyone knows? I know CFA told me how to long ago but forgot and dont found any samples in my library were i really used it.

Regards

Crome
Stealth Development Team & Support
Boydon
Neophyte
Neophyte
Posts: 36
Joined: 12.02.2012 18:06

Re: How to determine Type of Variables on Fly[Pascal]

Post by Boydon »

You can use VarType builtin function.

Code: Select all

Program New;
var
  myVar : Variant;
  myType : TVarType;
begin
 myVar := 'Hello Word'
 myType := VarType(myVar);
 Case myType of
  varEmpty     : AddToSystemJournal('The variant is not assigned.');
  varNull      : AddToSystemJournal('The variant is Null.');
  varSmallint  : AddToSystemJournal('The varian is a 16-bit signed integer.');
  varInteger   : AddToSystemJournal('The varian is a 32-bit signed integer.');
  varSingle    : AddToSystemJournal('The varian is a single-precision floating-point value.');
  varDouble    : AddToSystemJournal('The varian is a double-precision floating-point value.');
  varCurrency  : AddToSystemJournal('The varian is a currency floating-point value.');
  varDate      : AddToSystemJournal('The varian is a date and time value.');
  varOleStr    : AddToSystemJournal('The varian is a reference to a dynamically allocated UNICODE string.');
  varDispatch  : AddToSystemJournal('The varian is a reference to an Automation object.');
  varError     : AddToSystemJournal('The varian is a operating system error code.');
  varBoolean   : AddToSystemJournal('The varian is a 16-bit boolean.');
  varVariant   : AddToSystemJournal('The varian is a a variant.');
  varUnknown   : AddToSystemJournal('The varian is a reference to an unknown object.');
  varShortInt  : AddToSystemJournal('The varian is a 8-bit signed integer.');
  varByte      : AddToSystemJournal('The varian is a a byte.');
  varWord      : AddToSystemJournal('The varian is a unsigned 16-bit value.');
  varLongWord  : AddToSystemJournal('The varian is a unsigned 32-bit value.');
  varInt64     : AddToSystemJournal('The varian is a 64-bit signed integer.');
  varStrArg    : AddToSystemJournal('The varian is a COM-compatible string.');
  varString	 : AddToSystemJournal('The varian is a reference to a dynamically allocated string.');
 else
   AddToSystemJournal('Unknown type')
 end;
end.
Post Reply