Comparison of Pascal and Delphi: Difference between revisions

Content deleted Content added
No edit summary
General editing, together with an additional point 10 re differences in RTL philosophy
Line 1:
{{ProgLangCompare}}
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>http://docwiki.embarcadero.com/RADStudio/XE2/en/Delphi_Reference</ref>). Since first released, it has become the most popular commercial Pascal implementation.
This article is a '''comparison between Pascal and Delphi''' because Borland, the original manufacturer of [[CodeGear Delphi|Delphi]], once used ''Delphi'' for their version of the [[Pascal programming language|Pascal]]-based [[programming language]] used in the product, which is otherwise known as [[Object Pascal]]. Compatibles still maintain the Object Pascal designation because Delphi is a registered trademark.
 
[[PascalWhile (programmingdeveloping language)|Pascal]] is a [[programming language]], developed in 1970 by [[Niklaus Wirth]]. The original Pascal employed a [[Bootstrapping_(compilers)|bootstrapping]] constructprocedure wherein which each successivelynewer moreversion complicatedof the Pascal compiler was written and compiled thewith nextits iterationpredecessor. Thus, the compiler 'P2' compiler was written in the dialect compilable by 'P1', and could'P3' in turn compilewas P3,written in 'P2' and suchso on, all the way till 'P5'. whichThe implemented'P5' "full"compiler implemented Pascal in its final state as defined by Wirth, and wassubsequently morebecame optimizedstandardardised as 'ISO 7185 Pascal'.
 
[[The Borland]] Corporationdialect, like the wildly popular [[UCSD Pascal]] before themit, took the 'P4' subsetversion compilerof the language as theirits basis for their Turbo Pascal range, probablyrather becausethan theyWirth's consideredfinal it more efficient on the [[microcomputer|micros]] they were targetingrevision. OverAfter timemuch theirevolution dialectindependent implementedof manyStandard UCSD extensions toPascal, the originalBorland Pascalvariant likebecame the "string"basis type. Their language went through several versions and names, such as [[Turbo Pascal]], Borland Pascal, and finally [[Borlandfor Delphi|Delphi]] Pascal. This page briefly goes over the differences between thoseDelphi dialectsand ofStandard the languagePascal. It does '''not''' go into theDelphi-specific extensions providedto bythe Delphilanguage, thatwhich isare thenumerous subject of a Delphi page. Rather it just covers the differences that exist between theand basestill implementationsincreasing.
 
== Differences between theStandard languagesPascal and Delphi ==
==Terminology==
It is correct to refer to "Pascal" in general as Niklaus Wirth's original language (and derivatives) and Borland's dialect as "Delphi". When referring to Borland's previous dialects, the terms "Turbo Pascal", and "Borland Pascal" apply.
 
1. The way procedures and functions can be passed as parameters differs: Delphi requires explicit procedural types to be declared where Standard Pascal does not.
The term "ISO 7185" or "ISO 7185 Pascal" is used here as synonymous with Niklaus Wirth's programming language Pascal. The ISO 7185 standard is the standardized version of [[Niklaus Wirth]]'s language, as he has stated several times.
 
2. Delphi does not support so called 'intraprocedural gotos', in which [[goto]] statements may reference targets outside the current procedure/function body.
== Differences between the languages ==
 
3. No file buffer variable handling. Standard Pascal has file "'buffer variables"', andtogether "with 'get"' and "'put"' standard procedures tothat operate on them. ThisNeither functionalityare is not presentsupported in Borland Delphi.
Because Borland Delphi is a widely used version of Pascal, it is useful to compare the two languages. Note that here are presented only the differences between Borland Delphi and the basic ISO 7185 standard. Undiscussed are any extensions provided by Borland Delphi. In other words, this section answers the question "why doesn't my standard Pascal program run under Borland Delphi?", and perhaps "what can I write in Borland Delphi that will also be compatible with the ISO 7185 standard?".
 
4. Given a variant record in Standard Pascal, the size of a particular variant can be specified. Delphi does not support this form of 'sized' dynamic variable allocation:
1. Procedures and functions may not appear as parameters (it is true that it can be done, but a non-standard syntax must be used).
 
2. [[Goto]] statements cannot reference targets outside procedure/function bodies (so called "intraprocedural gotos").
 
3. No file buffer variable handling. Standard Pascal has file "buffer variables", and "get" and "put" procedures to operate on them. This functionality is not present in Borland Delphi.
 
4. No "sized" dynamic variable allocation. Given a variant record, the size of a particular variant cannot be specified as per the standard. I.e., the following statement is invalid:
 
<source lang="pascal">
Wherenew(p, t) //where t is a variant record tag type.; does not compile in Delphi
new(p, t)
</source>
 
5. The functions "'pack"' and "'unpack"' are not implemented in Delphi.
Where t is a variant record tag type.
 
5. The functions "pack" and "unpack" are not implemented.
 
6. The Delphi compiler does not treat { and (*, } and *) are notas synonyms oflike eachStandard otherPascal asrequires. requiredIn by theother standard. I.e.:words,
 
<source lang="pascal">
Line 37 ⟶ 28:
</source>
 
is not valid in Borland Delphi. Instead, (Delphi uses the scheme of allowing the different comment types to indicate nested comments). It is valid in Turbo Pascal though.
 
7. DoesDelphi does not replace eoln with space as the Pascal standard requires. When reading through the end of a line, the eoln character is supposed to be replaced with a space in ISO 7185. Instead, reading through eoln in Borland Delphi gives the character code for carriage return (13), followed by line feed (10).
 
8. Numbers and booleans are not printed out in their "'default"' field widths by Delphi's version of the Write and WriteLn standard procedures, butbeing areinstead printed in the minimum amount of space. For example:, in Delphi,
 
<source lang="pascal">
Line 55 ⟶ 46:
</source>
 
However, Standard Pascal requires it to be equivalent to the following (TotalWidth is implementation-defined):
in Delphi, but:
 
<source lang="pascal">
Line 62 ⟶ 53:
</source>
 
Similarly, for booleans,
in ISO 7185, where TotalWidth is implementation-defined.
 
For booleans:
 
<source lang="pascal">
Line 71 ⟶ 60:
</source>
 
is equivalent to:
 
<source lang="pascal">
Line 78 ⟶ 67:
</source>
 
in Delphi, but:
 
<source lang="pascal">
Line 85 ⟶ 74:
</source>
 
in ISO 7185, where TotalWidth is implementation-defined.
 
9. Temporary files are not supported. Executingby resetDelphi using traditional Pascal I/O - executing Reset() or rewriteRewrite() results in an error, where under Delphi. Under standardStandard Pascal it opens a temporary file that exists only for the runduration of the program before being automatically deleted.
 
10. Notwithstanding the fact Delphi still allows using much of the traditional Pascal RTL, Delphi-specific library functionality is generally implemented in ordinary Delphi code that uses, rather than adds to, compiler-provided intrinsics. This philosophy contrasts to Standard Pascal, whose RTL must be provided by the compiler. For example, in Standard Pascal, the 'file' type is an intrinsic type - sort of like a record, but another compiler-defined type alongside records. In contrast, the TFileStream class in Delphi is an ordinary Delphi class written in ordinary Delphi code. Similarly, the Read, ReadLn, Write and WriteLn standard procedures have signatures that are not themselves legal Pascal signatures. While Delphi still implements them, only vary rarely do Delphi-specific RTL routines require similarly special handling: rather, the language was evolved to include features such as 'open arrays', default parameters and procedural overloading that can be used by user-written routines too.
 
== References ==
 
<references />
9. Temporary files are not supported. Executing reset() or rewrite() results in an error under Delphi. Under standard Pascal it opens a temporary file that exists only for the run of the program.
 
== See also ==