Reputation: 4884
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.
Upvotes: 14
Views: 2272
Reputation:
string
must be a reserved word, because it is not exclusively used to refer to the type System.[Ansi|Unicode]String
. If string
were a simple alias for some internal compiler type, then string[20]
would no longer work. This is not a problem for Integer
, because Integer
always means nothing more than "the type System.Integer
".
Upvotes: 6
Reputation: 136401
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.
Upvotes: 6