Download objects

Transcript
02: Variables and Data Types - 45
'Marco Cantu'''
The two quotes stand for a quote within the string, while the third consecutive quote
marks the end of the string. Also note that a string literal must be written on a single
line, but you can concatenate multiple string literals using the + sign. If you want to
have the new line or line break within the string, don't write it on two lines, but concatenate the two elements with the sLineBreak system constant (which is platform
specific), as in:
'Marco' + sLineBreak + 'Cantu'''
Assignment Statements
Assignments in Object Pascal use the colon-equal operator (:=), an odd notation for
programmers who are used to other languages. The = operator, which is used for
assignments in many other languages, in Object Pascal is used to test for equality.
note
The := operators comes from a Pascal predecessor, Algol, a language few of todays developers
have heard of (let even used). Most of today's languages avoid the := notation and favor the =
assignment notation.
By using different symbols for an assignment and an equality test, the Pascal compiler (like the C compiler) can translate source code faster, because it doesn't need to
examine the context in which the operator is used to determine its meaning. The use
of different operators also makes the code easier for people to read. Truly Pascal
picked two different operators than C (and syntactic derivatives like Java, C#,
JavaScript), which uses = for assignment and == for equality test.
note
For the sake of completeness I should mention JavaScript has also a === operator, but that's
something that even most JavaScript programmers get confused about.
The two elements of an assignment are often called lvalue and rvalue, for left value
(the variable or memory location you are assigning to) and right value, the value of
the expressions being assigned. While the rvalue can be an expression, the lvalue
must refer (directly or indirectly) to a memory location you can modify. There are
some data types that have specific assignment behaviors which I'll cover in due time.
The other rule is that the type of the lvalue and of the rvalue must match, or there
must be an automatic conversion between the two, as explained in the next section.
Marco Cantù, Object Pascal Handbook