Declaring variables in Delphi brought me to consider a thing that I can't understand.
The question is this: declaring strings, one can observe that string
is a reserved word, while declaring other data types, say integers, the data type qualifier is not a reserved word but an identifier (i.e. Integer
, the capital I tells so).
In fact, Delphi lets you go to the definition of Integer
, which you discover it is contained within the System unit, but it is only representative, because there is a comment stating that some constants (like True
), identifiers (like Integer
), functions and procedures are directly built into the compiler.
I can't figure out the reasons behind this choice.
Could someone help?
A little explanation of the difference between string
and Integer
types. The next code
type
Integer = Char;
var
I: Integer;
begin
I:= 'A';
ShowMessage(I);
end;
is correct and works as expected, while the next line
type
string = Integer;
gives compile-time error.
A declaration defines an identifier (such as the name of a function or variable) that can be used in expressions and statements, and, where appropriate, allocates memory for the identifier. This topic introduces the Delphi language character set, and describes the syntax for declaring: Identifiers.
In a computer language, a reserved word (also known as a reserved identifier) is a word that cannot be used as an identifier, such as the name of a variable, function, or label – it is "reserved from use". This is a syntactic definition, and a reserved word may have no user-defined meaning.
Reserved Words in Pascal For example, the words, program, input, output, var, real, begin, readline, writeline and end are all reserved words.
Keywords have a special meaning in a language, and are part of the syntax. Reserved words are words that cannot be used as identifiers (variables, functions, etc.), because they are reserved by the language. In practice most keywords are reserved words and vice versa.
As far i know string
is a reserved word since the Turbo Pascal times. So the reason to keep it in this way must be for compatibility.
Pascal -> Turbo Pascal - > Object Pascal -> Delphi.
Check these resources.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With