Comparison of Pascal and Delphi

Short description: Programming language

Programming language comparisons

* General comparison
* Assignment
* Basic syntax
* Basic instructions
* Comments
* Control flow
* Foreach loops
* While loops
* For loops
* Do-while
* Exception handling
* Enumerated types
* Generators
* Anonymous functions
* Conditional expressions
* Functional instructions
* Arrays
* Associative arrays
* Scope
* String operations
* String functions
* Higher-order functions
* Type systems
* List comprehension
* Object-oriented programming
* Object-oriented constructors
* Operators

* Evaluation strategy
* List of "Hello World" programs

* Languages with dependent types
* Comparison of type systems

* * *

Comparison of individual languages

* ALGOL 58's influence on ALGOL 60
* ALGOL 60: Comparisons with other languages
* Comparison of ALGOL 68 and C++
* ALGOL 68: Comparisons with other languages
* Compatibility of C and C++
* Comparison of Pascal and Borland Delphi
* Comparison of Object Pascal and C
* Comparison of Pascal and C
* Comparison of Java and C++
* Comparison of C# and Java
* Comparison of C# and Visual Basic .NET
* Comparison of Visual Basic and Visual Basic .NET

* v
* t
* e

Pascal is a programming language devised by Niklaus Wirth in the late 1960s and early 1970s. Originally produced by Borland Software Corporation, Delphi is composed of an IDE, set of standard libraries, and a Pascal-based language commonly called either Object Pascal, Delphi Pascal, or simply 'Delphi' (Embarcadero's current documentation refers to it as 'the Delphi language (Object Pascal)'[1]). Since first released, it has become the most popular commercial Pascal implementation.

While developing Pascal, Wirth employed a bootstrapping procedure in which each newer version of the Pascal compiler was written and compiled with its predecessor. Thus, the 'P2' compiler was written in the dialect compilable by 'P1', 'P3' in turn was written in 'P2' and so on, all the way till 'P5'. The 'P5' compiler implemented Pascal in its final state as defined by Wirth, and subsequently became standardised as 'ISO 7185 Pascal'.

The Borland dialect, like the popular UCSD Pascal before it, took the 'P4' version of the language as its basis, rather than Wirth's final revision. After much evolution independent of Standard Pascal, the Borland variant became the basis for Delphi. This page goes over the differences between Delphi and Standard Pascal. It does not go into Delphi-specific extensions to the language, which are numerous and still increasing.

## Contents

* 1 Exclusive features
* 1.1 Modulo with negative dividend
* 1.2 Nested comments
* 1.3 Procedural data types
* 1.4 Conversion of newline characters
* 2 Additional or missing features
* 2.1 Global goto
* 2.2 Buffer variables
* 2.3 Discriminated variant record allocation
* 2.4 Temporary files
* 2.5 Packing
* 2.6 Missing default write width
* 2.7 Overloading
* 2.8 Default parameter values
* 3 Peculiar implementation characteristics
* 3.1 Standard write width
* 4 References
* 5 Further reading
* 6 External links

## Exclusive features

Following features are mutually exclusive. The Standard Pascal implementation is not accepted by Delphi and vice versa, the Delphi code is not acceptable in Standard Pascal.

### Modulo with negative dividend

Standard Pascal has a Euclidean-like definition of the `mod` operator whereas Delphi uses a truncated definition.

### Nested comments

Standard Pascal requires that the comment delimiters `{` and the bigram `(*`, as well as `}` and `*)` are synonymous to each other.[2] In Delphi, however, a block comment started by `{` must be closed with a `}`.[3] The bigramm `*)` will only close any comment that started with `(*`.[3] This scheme allows for nested comments.

### Procedural data types

The way procedures and functions can be passed as parameters differs: Delphi requires explicit procedural types to be declared where Standard Pascal does not.[4]

comparison procedural data types  Standard Pascal | Delphi

|

program proceduralDataType(output);

{ `printYIntersect` has one procedural parameter: }
procedure printYIntersect(function f(x: real): real);
begin
writeLn(f(0.0));
end;
{ Standard Pascal does not have procedural “pointers.” }
function f(x: real): real;
begin
f := cos(x);
end;
{ ─── MAIN ───────────────────────────────────────────── }
begin
printYIntersect(f);
end.

type
TFunc = function(x: real): real;

procedure printYIntersect(f: TFunc);
begin
writeLn(f(0.0));
end;

function f(x: real): real;
begin
f := cos(x);
end;
// ─── MAIN ─────────────────────────────────────────────
begin
printYIntersect(@f);
end.

### Conversion of newline characters

Various computer systems show a wide variety how to indicate a newline. This affects the internal representation of `text` files which are composed of a series of “lines”. In order to relieve the programmer from any associated headaches, Standard Pascal mandates that reading an “end-of-line character” returns a single space character. To distinguish such an “end-of-line” space character from a space character that is actually genuine payload of the line, `EOLn` becomes `true`.

Delphi does not show this behavior. Reading a newline will return whatever character sequence represents a newline on the current host system, for example two `char` values `chr(13)` (carriage return) plus `chr(10)` (line feed).[3]

## Additional or missing features

Following features are present or missing in either language.

### Global `goto`

Standard Pascal permits a `goto` to any `label` defined in scope. In Delphi a `goto` must be within the current routine, i. e. may not leave the `begin … end`-frame.[3]

program jumpAround;
label
999;
procedure foo;
begin
{ This is not permitted in Delphi: }
goto 999;
end;
begin
foo;
999: ;
end.

### Buffer variables

Delphi does not support buffer variables and associated standard routines `get` and `put`.[3]

program copy(input, output);
begin
while not EOF(input) do
begin
{ Copy file buffers. Not supported by Delphi }
output↑ := input↑;

{ Input↑ contains a space if a new-line occurred. }
if EOLn(input) then
begin
writeLn(output);
end
else
begin
put(output);
end;

{ Advance reading cursor. }
get(input);
end;
end.

### Discriminated variant record allocation

In Standard Pascal allocating memory for a variant `record` may indicate a specific variant. This allows implementations to allocate the least amount of really necessary memory. Delphi does not support this.[3]

program variantRecord;
type
sex = (female, male);
clothingMeasures = record
girth: real;
case gender: sex of
female: (underbust: real);
male: ( );
end;
var
size: clothingMeasures;
begin
{ NB: No space allocated for `underbust`. }
new(size, male);
end.

### Temporary files

In Delphi any file must be backed by a file in the file system. That means any `file` needs to be associated with a file name with Delphi's `assign` procedure. In contrast, Standard Pascal is usable without file names. The following will produce a run-time error with Delphi.[3]

program temporaryFile(output);
var
FD: text;
begin
rewrite(FD);
writeLn(FD, 'Hello world!');
end.

### Packing

Delphi does not implement the standard procedures `pack` and `unpack`.[3] Regardless, transferring data between packed and unpacked data types is an easy feat. However, Delphi allows a class, object, or record to be declared as "packed", which minimizes the space they use.

### Missing default `write` width

Delphi does not associate the data type `Boolean` with a default width if specified as `write`/`writeLn` parameters.[3] Delphi demonstrates the behavior as usual for character-strings.

### Overloading

Delphi permits overloading routines. In Standard Pascal identifiers must be unique in every block.

function f(x: integer): real;
begin
result := sin(x);
end;

function f(x: real): real;
begin
result := cos(x);
end;
// ─── MAIN ─────────────────────────────────────────────
begin
// Note the different data types.
writeLn(f(3));
writeLn(f(3.0));
end.

### Default parameter values

Delphi permits default parameters.

## Peculiar implementation characteristics

### Standard `write` width

In Pascal, if the destination file is a `text` file, the parameters to `write`/`writeLn` have an implemention-defined default total width. In Delphi, for `integer` values this is simply `1`. That means always the least amount of space is occupied.[3] Other compilers have shown default widths of, for example, `20` allowing for a fine tabular look at no cost of extra code.

comparison default `write` width  source code fragment

writeLn(1);
writeLn(23456789);

produces in
Standard Pascal (GPC) | Delphi

23456789

23456789

## References

1. ↑ "Delphi Reference - RAD Studio XE2". http://docwiki.embarcadero.com/RADStudio/XE2/en/Delphi_Reference.
2. ↑ van der Heijden, Jan-Jaap; Gerwinski, Peter; Heckenbach, Frank; deBoer, Berend; Freche, Dominik; Lange, Eike; Lewis, Peter. "The GNU Pascal Manual". A QuickStart Guide from Borland Pascal to GNU Pascal. https://www.GNU-Pascal.de/gpc/Comments.html#Comments.
3. ↑ 3.00 3.01 3.02 3.03 3.04 3.05 3.06 3.07 3.08 3.09 Moore, Scott (2022-12-02). "Standard Pascal FAQ". Q. What are the differences between Borland Delphi and the ISO 7185 standard?. https://www.MooreCAD.com/standardpascal/pascalfaq.html#Q. What are the differences between Borland Del.
4. ↑ Reagan, John (1995-04-03). "Pascal Standards FAQ". Comparison of Borland Pascal to the Pascal standards. http://Pascal-Central.com/extpascal.html#anchor-6.

## Further reading

* Kathleen Jansen and Niklaus Wirth: PASCAL - User Manual and Report. Springer-Verlag, 1974, 1985, 1991, ISBN 0-387-97649-3, ISBN 0-387-90144-2, and ISBN 3-540-90144-2 [1]
* Niklaus Wirth: The Programming Language Pascal. Acta Informatica, 1, (Jun 1971) 35–63
* ISO/IEC 7185: Programming Languages - PASCAL. [2]
* Doug Cooper: Standard Pascal: User Reference Manual. W. W. Norton & Company, 1983, ISBN 0-393-30121-4, ISBN 978-0-393-30121-2

## External links

* The ISO 7185 Pascal web site
* Pascal standards documents

* v
* t
* e

Pascal programming language family

Dialects|

* Pascal
* Object Pascal
* Pascal Script
* Oxygene
* Clascal
* Concurrent Pascal
* SuperPascal

Compilers|

| Current|

* Delphi
* Oxygene
* PocketStudio
* HP Pascal
* IP Pascal
* Free Pascal (Lazarus)
* PascalABC.NET
* GNU Pascal
* Turbo51
* MIDletPascal
* Pic Micro Pascal
* ACK

|

Historic|

* Virtual Pascal
* Apple Pascal
* Turbo Pascal
* Microsoft Pascal
* UCSD Pascal
* JRT
* Pascal/MT+

API|

* CLX
* FCL
* FireMonkey
* LCL
* Object Windows Library
* OpenWire
* RTL
* Turbo Vision
* Visual Component Library

* Comparison of Pascal and C
* Comparison of Pascal and Delphi

Related to
ALGOL (1958)
Modula-2 (1977)
Ada (1983)
Oberon (1986)
Modula-3 (1988)
Oberon-2 (1991)
Component Pascal (1991)

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Comparison of Pascal and Delphi. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Comparison_of_Pascal_and_Delphi&oldid=4158283"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template