Comparison of Pascal and Delphi: Difference between revisions

Content deleted Content added
more structure content
add some
Line 1:
{{Short description|Programming language}}
{{ProgLangCompare}}
{{use mdy dates|date=April 2023}}
Devised by [[Niklaus Wirth]] in the late 1960s and early 1970s, [[Pascal (programming language)|Pascal]] is a [[programming language]]. Originally produced by [[Borland]] Software Corporation, [[Embarcadero 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)'<ref>{{Cite web|url=http://docwiki.embarcadero.com/RADStudio/XE2/en/Delphi_Reference|title = Delphi Reference - RAD Studio XE2}}</ref>). Since first released, it has become the most popular commercial Pascal implementation.
 
While developing Pascal, Wirth employed a [[Bootstrapping (compilers)|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 <em>''not</em>'' go into Delphi-specific extensions to the language, which are numerous and still increasing.
 
== 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 an Euclidean-like definition of the [[Modulo#In programming languages|<syntaxhighlight lang="pascal" inline>mod</syntaxhighlight> operator]] whereas Delphi uses a truncated definition.
 
=== Nested comments ===
Standard Pascal requires that the comment delimiters <syntaxhighlight lang="pascal" inline>{</syntaxhighlight> and the bigramm <syntaxhighlight lang="pascal" inline>(*</syntaxhighlight>, as well as <syntaxhighlight lang="pascal" inline>}</syntaxhighlight> and <syntaxhighlight lang="pascal" inline>*)</syntaxhighlight> are synonymous to each other.
In Delphi, however, a block comment started by <syntaxhighlight lang="pascal" inline>{</syntaxhighlight> ''must'' be closed with a <syntaxhighlight lang="pascal" inline>}</syntaxhighlight>.<ref name="moore"/>
The bigramm <syntaxhighlight lang="pascal" inline>*)</syntaxhighlight> will only close any comment that started with <syntaxhighlight lang="pascal" inline>(*</syntaxhighlight>.<ref name="moore"/>
This scheme allows for ''nested'' comments at the expense of compiler complexity.
 
=== 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.<ref name="reagan"/>
{| class="wikitable" style="margin: auto;"
|+ comparison procedural data types
Line 65 ⟶ 69:
 
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 <syntaxhighlight lang="delphi" inline>char</syntaxhighlight> values <syntaxhighlight lang="delphi" inline>chr(13)</syntaxhighlight> (carriage return) plus <syntaxhighlight lang="delphi" inline>chr(10)</syntaxhighlight> (line feed).<ref name="moore"/>
 
== Additional or missing features ==
Line 72 ⟶ 76:
=== Global <syntaxhighlight lang="pascal" inline>goto</syntaxhighlight> ===
Standard Pascal permits a <syntaxhighlight lang="pascal" inline>goto</syntaxhighlight> to any <syntaxhighlight lang="pascal" inline>label</syntaxhighlight> defined in scope.
In Delphi a <syntaxhighlight lang="delphi" inline>goto</syntaxhighlight> must be within the current routine, i. e. may not leave the <syntaxhighlight lang="delphi" inline>begin … end</syntaxhighlight>-frame.<ref name="moore"/>
<syntaxhighlight lang="pascal" highlight="6,7">program jumpAround;
label
Line 87 ⟶ 91:
 
=== Buffer variables ===
Delphi does not support buffer variables and associated standard routines <syntaxhighlight lang="pascal" inline>get</syntaxhighlight> and <syntaxhighlight lang="pascal" inline>put</syntaxhighlight>.<ref name="moore"/>
<syntaxhighlight lang="pascal" highlight="5,6,15,19">program copy(input, output);
begin
Line 113 ⟶ 117:
In Standard Pascal allocating memory for a variant <syntaxhighlight lang="pascal" inline>record</syntaxhighlight> may indicate a specific variant.
This allows implementations to allocate the least amount of ''really'' necessary memory.
Delphi does not support this.<ref name="moore"/>
<syntaxhighlight lang="pascal" highlight="13,14">program variantRecord;
type
Line 134 ⟶ 138:
That means any <syntaxhighlight lang="delphi" inline>file</syntaxhighlight> needs to be associated with a file name with Delphi’s <syntaxhighlight lang="delphi" inline>assign</syntaxhighlight> procedure.
In contrast, Standard Pascal is usable without file names.
The following will produce a run-time error with Delphi.<ref name="moore"/>
<syntaxhighlight lang="pascal">program temporaryFile(output);
var
Line 144 ⟶ 148:
 
=== Packing ===
Delphi does not implement the standard procedures <syntaxhighlight lang="pascal" inline>pack</syntaxhighlight> and <syntaxhighlight lang="pascal" inline>unpack</syntaxhighlight>.<ref name="moore"/>
Regardless, transferring data between packed and unpacked data types is an easy feat, although the implementation might not be as efficient as a compiler vendor supplied implementation would be.
 
=== Missing default <syntaxhighlight lang="pascal" inline>write</syntaxhighlight> width ===
Delphi does not associate the data type <syntaxhighlight lang="pascal" inline>Boolean</syntaxhighlight> with a default width if specified as <syntaxhighlight lang="pascal" inline>write</syntaxhighlight>/<syntaxhighlight lang="pascal" inline>writeLn</syntaxhighlight> parameters.<ref name="moore"/>
Delphi demonstratetsdemonstrates the behavior as usual for character-strings.
 
=== Overloading ===
Line 177 ⟶ 181:
In Pascal, if the destination file is a <syntaxhighlight lang="pascal" inline>text</syntaxhighlight> file, the parameters to <syntaxhighlight lang="pascal" inline>write</syntaxhighlight>/<syntaxhighlight lang="pascal" inline>writeLn</syntaxhighlight> have an implemention-defined default total width.
In Delphi, for <syntaxhighlight lang="delphi" inline>integer</syntaxhighlight> values this is simply <syntaxhighlight lang="delphi" inline>1</syntaxhighlight>.
That means always the least amount of space is occupied.<ref name="moore"/>
Other compilers have shown default widths of, for example, <syntaxhighlight lang="pascal" inline>20</syntaxhighlight> allowing for a fine tabular look at no cost of extra code.
{| class="wikitable" style="margin: auto;"
Line 196 ⟶ 200:
23456789</syntaxhighlight>
|}
 
== See also ==
* [[Delphi (programming language)]]
* [[Comparison of Pascal and C]]
* [[Pascal (programming language)]]
 
== References ==
<references />
 
<ref name="reagan">{{cite web
<references />
| title = Pascal Standards FAQ
| at = Comparison of Borland Pascal to the Pascal standards
| first = John
| last = Reagan
| date = 1995-04-03
| url = http://pascal-central.com/extpascal.html#anchor-6
| archive-url = https://web.archive.org/web/20210928162340/http://pascal-central.com/extpascal.html#anchor-6
| archive-date = 2021-09-28
}}</ref>
<ref name="moore">{{cite web
| title = Standard Pascal FAQ
| at = Q. What are the differences between Borland Delphi and the ISO 7185 standard?
| first = Scott
| last = Moore
| date = 2022-12-02
| url = https://www.moorecad.com/standardpascal/pascalfaq.html#Q.%20What%20are%20the%20differences%20between%20Borland%20Del
| access-date = 2023-04-24
}}</ref>
</references>
 
== Further reading ==
Line 211 ⟶ 229:
* ISO/IEC 7185: ''Programming Languages - PASCAL.'' [http://www.moorecad.com/standardpascal/]
* Doug Cooper: ''Standard Pascal: User Reference Manual.'' W. W. Norton & Company, 1983, {{ISBN|0-393-30121-4}}, {{ISBN|978-0-393-30121-2}}
* Pascal standards documents [http://www.standardpascal.org/standards.html]
 
== External links ==
* The standard, ISO 7185 Pascal web site [httphttps://www.moorecad.com/standardpascal/ The ISO 7185 Pascal web site]
* [https://www.StandardPascal.org/standards.html Pascal standards documents]
 
{{Pascal programming language family}}
 
{{DEFAULTSORT:Pascal and Delphi comparison}}
[[Category:Pascal programming language family]]