Base Types



propertyicon.png String

String type is used when you wish to store a character string of any length. It uses the Unicode character set for the characters that comprise the string. Character type store a single character, and also use the Unicode character set.

Information String maps to JavaScript String object. Strings can be delimited by a single quote ('abc'). Explicit Unicode characters can be specified by using # followed by an integer codepoint (decimal or hexadecimal). Characters specified this way are always understood as Unicode codepoint.

Type Description
String A string value with a variable number of characters.
Char A single character.

String literals use the single quote (') character to identify themselves as such. Any single quotes enclosed inside of the literal must be escaped by prefacing them with another single quote. In addition, single character constants may be specified using their literal value or by prefacing their ordinal character set position with the pound sign (#) character. To reference a specific character in a string, use the left and right brackets ([]) with the 1-based integer position of the character being referenced.

Information Strings are immutable, meaning that they cannot be modified in-place by assigning new character values at specific positions in the string. They must always be copied and then assigned to a new string in order to be modified.

The unit SysUtils provides many utility functions for String, like:

String Methods
methodicon.png CharInSet
methodicon.png LeftStr
methodicon.png RightStr
methodicon.png Trim
methodicon.png TrimLeft
methodicon.png TrimRight
methodicon.png UpperCase
methodicon.png LowerCase
methodicon.png CompareStr
methodicon.png SameStr
methodicon.png CompareText
methodicon.png SameText
methodicon.png AnsiCompareText
methodicon.png AnsiSameText
methodicon.png AnsiCompareStr
methodicon.png AppendStr
methodicon.png Format
methodicon.png LocaleCompare
methodicon.png NormalizeStr
methodicon.png IsValidIdent
methodicon.png StringReplace
methodicon.png QuoteString
methodicon.png IsDelimiter
methodicon.png AdjustLineBreaks
methodicon.png WrapText

propertyicon.png Boolean

Information Boolean Stores True or False. Maps to JavaScript Boolean object. When casting a Boolean as an Integer, True maps to 1 and False maps to 0. When casting an Integer as a Boolean, 0 maps to False and all other values map to True.

Type Description
Boolean A logical true/false value.

The unit SysUtils provides many utility functions for Boolean, like:

Boolean Methods
methodicon.png StrToBool
methodicon.png BoolToStr
methodicon.png StrToBoolDef
methodicon.png TryStrToBool

propertyicon.png Numbers

Unlike many other programming languages, javaScript does not define different types of numbers, like integers, short, long, floating-point etc. JavaScript only supports double. All Pascal number types and enum values are mapped to this.

Exact numeric types are used when you wish to store a numeric value in its exact representation without accumulating rounding errors. Exact numeric literals use the minus (-) as the negative sign character, the plus (+) as the positive sign character, and scientific notation is supported. In addition, hexadecimal literals can be specified by prefacing the hexadecimal value with the dollar sign ($). Represents integer numbers.

Information Integer maps to JavaScript Number object and is therefore internally always represented as a floating-point number. The compiler will strive to keep the Number object with an integer value, though since Number is a double-precision float that value can exceed the 32 bits range and reach up to 53 bits for regular operands (+, -, <, etc.) are accurate from -4503599627370496 to 4503599627370495. Due to JavaScript limitations, value will be clamped to 32 bits for bitwise operands.

Type Range Size
Byte 0 .. 255 unsigned 8-bit
Shortint -128 .. 127 signed 8-bit
SmallInt -32768 .. 32767 signed 16-bit
Word 0 .. 65535 unsigned 16-bit
Integer -4503599627370496 .. 4503599627370495 signed 53-bit
Cardinal 0 .. 4294967295 unsigned 32-bit
Longint -2147483648 .. 2147483647 signed 32-bit
NativeUInt 0 .. 4503599627370495 unsigned 52-bit
NativeInt -4503599627370496 .. 4503599627370495 signed 53-bit
LongWord 0 .. 4294967295 unsigned 32-bit
Int64 -9223372036854775808 .. 9223372036854775807 signed 64-bit
QWord 0 .. 18446744073709551615 unsigned 64-bit

The unit SysUtils provides many utility functions for Integer, like:

Integer Methods
methodicon.png IntToStr
methodicon.png TryStrToInt
methodicon.png StrToIntDef
methodicon.png StrToInt
methodicon.png StrToNativeInt
methodicon.png StrToInt64
methodicon.png StrToInt64Def
methodicon.png TryStrToInt64
methodicon.png StrToQWord
methodicon.png StrToQWordDef
methodicon.png TryStrToQWord
methodicon.png StrToUInt64
methodicon.png StrToUInt64Def
methodicon.png TryStrToUInt64
methodicon.png StrToDWord
methodicon.png StrToDWordDef
methodicon.png TryStrToDWord
methodicon.png IntToHex

JavaScript numbers are always stored as double precision floating point numbers. This format stores numbers in 64 bits, where the number (the fraction) is stored in bits 0 to 51, the exponent in bits 52 to 62, and the sign in bit 63.

Approximate numeric types are used when you wish to store a numeric value in an approximate representation with a floating decimal point. Using approximate numeric types can cause rounding errors due to the fact that certain numbers such as 0.33 cannot be accurately represented using floating-point precision.

Information Double Represents double-precision floating-point numbers. Float maps to JavaScript Number object. Double can be represented in normal notation (3.1415) or in exponential notation (1.23e45). Maximum precision of 16 digits, are accurate from 5x10-324 to 1.7x10308.

Type Range Significant digits
Real ±2.9×10-39 .. 1.7×1038 11-12
Single ±1.5*10-45 .. 3.4*1038 7-8
Double 5*10-324 .. 1.7*10308 15-16
Extended 1.9*10-4932 .. 1.1*104932 19-20
Comp -2*1064 .. +2*1064-1 19-20
Currency -922337203685477.5808 .. 922337203685477.5807 19-20

The unit SysUtils provides many utility functions for Float, like:

Float Methods
methodicon.png FloatToDecimal
methodicon.png FloatToStr
methodicon.png FloatToStrF
methodicon.png TryStrToFloat
methodicon.png StrToFloatDef
methodicon.png StrToFloat
methodicon.png FormatFloat

propertyicon.png DateTime

Type Description
DateTime A date/time value containing the number of milliseconds since midnight on January 1, 1970.

The unit SysUtils provides many utility functions for DateTime, like:

Date/Time Methods
methodicon.png DateTimeToJSDate
methodicon.png JSDateToDateTime
methodicon.png DateTimeToTimeStamp
methodicon.png TimeStampToDateTime
methodicon.png MSecsToTimeStamp
methodicon.png TimeStampToMSecs
methodicon.png TryEncodeDate
methodicon.png TryEncodeTime
methodicon.png EncodeDate
methodicon.png EncodeTime
methodicon.png ComposeDateTime
methodicon.png DecodeDate
methodicon.png DecodeDateFully
methodicon.png DecodeTime
methodicon.png DateTimeToSystemTime
methodicon.png SystemTimeToDateTime
methodicon.png DayOfWeek
methodicon.png Date
methodicon.png Time
methodicon.png Now
methodicon.png IncMonth
methodicon.png IncAMonth
methodicon.png IsLeapYear
methodicon.png DateToStr
methodicon.png TimeToStr
methodicon.png DateTimeToStr
methodicon.png StrToDate
methodicon.png StrToTime
methodicon.png StrToDateTime
methodicon.png FormatDateTime
methodicon.png TryStrToDate
methodicon.png TryStrToTime
methodicon.png TryStrToDateTime
methodicon.png StrToDateDef
methodicon.png StrToTimeDef
methodicon.png StrToDateTimeDef
methodicon.png CurrentYear
methodicon.png ReplaceTime
methodicon.png ReplaceDate
methodicon.png FloatToDateTime

propertyicon.png JSValue

Information JSValue works similar to a JS variable. You can assign almost any value to it and it can be type casted to many types, for instance, Any array can be assigned to an array of JSValue. JSValue is useful for JS wrappers, when a variable can have multiple types. And it can be used for containers storing arbitrary data, e.g. a list of JSValue. A JSValue variable initial value is undefined.

Type Description
JSValue JSValue stores any pascal base, since you do not have to predefine the structure by hand.

The unit JS provides many utility functions for JSValue, like:

JSValue Methods
methodicon.png hasString
methodicon.png hasValue
methodicon.png isArray
methodicon.png isBoolean
methodicon.png isCallback
methodicon.png isChar
methodicon.png isClass
methodicon.png isClassInstance
methodicon.png isFunction
methodicon.png isInteger
methodicon.png isModule
methodicon.png isNull
methodicon.png isNumber
methodicon.png isObject
methodicon.png isRecord
methodicon.png isString
methodicon.png isUndefined
methodicon.png isDefined
methodicon.png isUTF16Char
methodicon.png isExt
methodicon.png jsInstanceOf
methodicon.png jsTypeOf
methodicon.png jsIsNaN
methodicon.png toNumber

Pas2JS pascal source code
var number: TFuncOfInt; MyInteger: Integer; MyDouble: Double; MyString: String; MyCharacter: Char; MyBoolean: Boolean; MyJSValue: JSValue; begin MyInteger := 100; // Assign 100 to the Integer variable MyInteger := $64; // Assign 100 as hexadecimal to the Integer variable MyDouble := -100.25; // Assign -100.25 to the Double variable MyDouble := 5E-324 * 1E1; MyString := 'This is a test'; // Assign "This is a test" // to the String variable MyString := #13+#10; // Assign a carriage return and // linefeed to the String variable MyCharacter := MyString[2]; // Assign the second character // from the String variable to // the Char variable MyString := 'Hello'#13#$0A'World'; console.log(MyString); MyBoolean := False; // Assign False to the Boolean variable MyJSValue := $64; console.log( Math.floor(Integer(MyJSValue)) ); MyJSValue := 13.535; console.log( Math.floor(Double(MyJSValue)) ); MyJSValue := True; MyJSValue := MyString[5]; end.
Type Mappings
Type
Integer = LongInt;
Cardinal = LongWord;
DWord = LongWord;
SizeInt = NativeInt;
SizeUInt = NativeUInt;
PtrInt = NativeInt;
PtrUInt = NativeUInt;
ValSInt = NativeInt;
ValUInt = NativeUInt;
ValReal = Double;
Real = Double;
Extended = Double;
Float = Double;
Int64 = NativeInt unimplemented;
UInt64 = NativeUInt unimplemented;
QWord = NativeUInt unimplemented;
Single = Double unimplemented;
Comp = NativeInt unimplemented;
NativeLargeUInt = NativeUInt;
UnicodeString = String;
WideString = String;
WideChar = char;
TDynArrayIndex = NativeInt;
TBooleanDynArray = array of Boolean;
TIntegerDynArray = array of Integer;
TStringDynArray = array of String;
TDoubleDynArray = array of Double;
TJSValueDynArray = array of JSValue;