Difference between revisions of "ReNamer:Pascal Script:Types"

From den4b Wiki
Jump to navigation Jump to search
(→‎Extra types: Strike out TStringsArray type)
(→‎String types: Commonly used encodings)
Line 74: Line 74:
 
|-
 
|-
 
| '''Char'''
 
| '''Char'''
| Stores a single Ansi character.
+
| Stores a single 8-bit character.
 
|-
 
|-
 
| '''String'''
 
| '''String'''
| Holds a sequence of Ansi characters of any length.
+
| Holds a sequence of 8-bit characters. Commonly used for ANSI or UTF-8 encoded text.
 
|-
 
|-
 
| '''AnsiChar'''
 
| '''AnsiChar'''
Line 86: Line 86:
 
|-
 
|-
 
| '''WideChar'''
 
| '''WideChar'''
| Stores a single Unicode character.
+
| Stores a single 16-bit character.
 
|-
 
|-
 
| '''WideString'''
 
| '''WideString'''
| Holds a sequence of Unicode characters of any length.
+
| Holds a sequence of 16-bit characters. Commonly used for UCS-2 or UTF-16 encoded text.
 +
|-
 +
| '''UnicodeChar'''
 +
| Alias for ''WideChar'' type.
 +
|-
 +
| '''UnicodeString'''
 +
| Alias for ''WideString'' type.
 
|}
 
|}
  
'''Note:''' [[Unicode]] article highlights the difference between Unicode and Ansi.
+
'''Note:''' The [[Unicode]] article highlights the differences between various encodings.
  
 
== Mixed types ==
 
== Mixed types ==

Revision as of 17:15, 1 October 2019

This page lists and explains all supported types in Pascal Script used within ReNamer.

Integer types

Type Size Lowest Value Highest Value
Byte 1 byte 0 255
ShortInt 1 byte -128 127
Word 2 bytes 0 65,535
SmallInt 2 bytes -32,768 32,767
Cardinal 4 bytes 0 4,294,967,295
Integer 4 bytes -2,147,483,648 2,147,483,647
Int64 8 bytes -9,223,372,036,854,775,808 9,223,372,036,854,775,807

Floating point types

Type Size Range
Single 4 bytes 1.5 x 10-45 .. 3.4 x 1038
Double 8 bytes 5.0 x 10-324 .. 1.7 x 10308
Extended 10 bytes 3.6 x 10-4951 .. 1.1 x 104932

String types

Type Description
Char Stores a single 8-bit character.
String Holds a sequence of 8-bit characters. Commonly used for ANSI or UTF-8 encoded text.
AnsiChar Alias for Char type.
AnsiString Alias for String type.
WideChar Stores a single 16-bit character.
WideString Holds a sequence of 16-bit characters. Commonly used for UCS-2 or UTF-16 encoded text.
UnicodeChar Alias for WideChar type.
UnicodeString Alias for WideString type.

Note: The Unicode article highlights the differences between various encodings.

Mixed types

Type Description
Boolean Provides an enumeration of the logical True and False values.
Array Single and multi dimensional indexable sequences of data.
Record Provides means of collecting together a set of different data types into one named structure.
Variant Provides a flexible general purpose data type.
PChar Pointer to a Char value, and can also be used to point to characters within a string.

Extra types

Several extra types have been defined to simplify the use of some functions.

Type Declared as Description
TDateTime Double Holds date and time
TStringsArray Array of WideString Holds an indexable sequence of WideString.
Deprecated in v5.74.4 Beta. Please use TWideStringArray instead.
TWideStringArray Array of WideString Holds an indexable sequence of WideString.
Added in v5.74.4 Beta. Replaces ambiguous TStringsArray type.
TAnsiStringArray Array of AnsiString Holds an indexable sequence of AnsiString.
Added in v5.74.4 Beta.

Enumerations and Sets

For example, the Boolean data type is itself an enumeration, with two possible values: True and False. If you try to assign a different value to a Boolean variable, the code will not compile.

Example Description
type
  TDay = (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
var
  Day: TDay;
begin
  Day := Mon;
  if Day <> Tue then
    Day := Wed;
end.
An enumeration is simply a fixed range of named values
type
  TDay = (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
  TDays = set of TDay;
var
  Days: TDays;
begin
  Days := [Mon, Tue, Wed];
  if Sun in Days then
    Days := Days - [Sun];
end.
Whereas enumerations allow a variable to have one, and only one, value from a fixed number of values, sets allow you to have any combination of the given values