Object Pascal

Last updated
Object Pascal
Paradigms Imperative, structured, object-oriented, functional (Delphi dialect only), component-based, event-driven, generic
Family Wirth Pascal
Designed by Larry Tesler (Apple)
Niklaus Wirth (for Apple)
Anders Hejlsberg (Borland) [1]
Developers Apple Computer (initial)
Borland International [1]
First appeared1986;35 years ago (1986)
Typing discipline Static and dynamic (dynamic typing through variants, array of const, and RTTI), strong, safe
Scope Lexical (static)
Platform ARM, x86, PowerPC, ppc64, SPARC, MIPS, CLI, Java, Cocoa
Filename extensions .p, .pp, .pas
Major implementations
Delphi (x86, ARM), Free Pascal (x86, PowerPC, ppc64, SPARC, MIPS, ARM), Oxygene (CLI, Java, Native Cocoa), Smart Mobile Studio (JavaScript)
Dialects
Apple, Turbo Pascal, Free Pascal (using objfpc or delphi mode), Delphi, Delphi.NET, Delphi Web Script, Oxygene
Influenced by
Pascal, Simula, Smalltalk
Influenced
C#, Genie, Java, Nim, C/AL

Object Pascal is an extension to the programming language Pascal that provides object-oriented programming (OOP) features such as classes and methods.

Contents

The language was originally developed by Apple Computer as Clascal for the Lisa Workshop development system. As Lisa gave way to Macintosh, Apple collaborated with Niklaus Wirth, the author of Pascal, to develop an officially standardized version of Clascal. This was renamed Object Pascal. Through the mid-1980s, Object Pascal was the main programming language for early versions of the MacApp application framework. The language lost its place as the main development language on the Mac in 1991 with the release of the C++-based MacApp 3.0. Official support ended in 1996.

Symantec also developed a compiler for Object Pascal for their Think Pascal product, which could compile programs much faster than Apple's own Macintosh Programmer's Workshop (MPW). Symantec then developed the Think Class Library (TCL), based on MacApp concepts, which could be called from both Object Pascal and THINK C. The Think suite largely displaced MPW as the main development platform on the Mac in the late 1980s.

Symantec ported Object Pascal to the PC, and developed a similar object framework on that platform. In contrast to TCL, which eventually migrated to C++, the PC libraries remained mainly based on Pascal.

Borland added support for object-oriented programming to Turbo Pascal 5.5, which would eventually become the basis for the Object Pascal dialect used in Delphi. Delphi remained mainstream for business applications on the PC into the early 2000s, and was partly displaced in the 2000s with the introduction of the .NET Framework.

History

Apple Pascal

Pascal became a major language in the programming world in the 1970s, with high-quality implementations on most minicomputer platforms and microcomputers. Among the later was the UCSD Pascal system, which compiled to an intermediate p-System code format that could then run on multiple platforms. Apple licensed UCSD and used it as the basis for their Apple Pascal system for the Apple II and Apple III.

Pascal became one of the major languages in the company in this period. With the start of the Apple Lisa project, Pascal was selected as the main programming language of the platform, although this time as a compiler in contrast to the p-System interpreter.

Clascal and Apple's early Object Pascal

Object Pascal is an extension of the Pascal language that was developed at Apple Computer by a team led by Larry Tesler in consultation with Niklaus Wirth, the inventor of Pascal. [2] It is descended from an earlier object-oriented version of Pascal named Clascal, which was available on the Lisa computer.

Object Pascal was needed to support MacApp, an expandable Macintosh application framework that would now be termed a class library. Object Pascal extensions, and MacApp, were developed by Barry Haynes, Ken Doyle, and Larry Rosenstein, and were tested by Dan Allen. Larry Tesler oversaw the project, which began very early in 1985 and became a product in 1986.

An Object Pascal extension was also implemented in the Think Pascal integrated development environment (IDE). The IDE includes the compiler and an editor with syntax highlighting and checking, a powerful debugger, and a class library. Many developers preferred Think Pascal over Apple's implementation of Object Pascal because Think Pascal offered a much faster compile–link–debug cycle, and tight integration of its tools. The last official release of Think Pascal was 4.01, in 1992. Symantec later released an unofficial version 4.5d4 at no charge.

Apple dropped support for Object Pascal when they moved from Motorola 68000 series chips to IBM's PowerPC architecture in 1994. MacApp 3.0, for this platform, was rewritten in C++.

Borland, Inprise, CodeGear, and Embarcadero years

In 1986, Borland introduced similar extensions, also named Object Pascal, to the Turbo Pascal product for the Macintosh, and in 1989 for Turbo Pascal 5.5 for DOS. When Borland refocused from DOS to Windows in 1994, they created a successor to Turbo Pascal, named Delphi, and introduced a new set of extensions to create what is now known as the Delphi language.

The development of Delphi started in 1993 and Delphi 1.0 was officially released in the United States on 14 February 1995. While code using the Turbo Pascal object model could still be compiled, Delphi featured a new syntax using the keyword class in preference to object, the Create constructor and a virtual Destroy destructor (and negating having to call the New and Dispose procedures), properties, method pointers, and some other things. These were inspired by the ISO working draft for object-oriented extensions, but many of the differences from Turbo Pascal's dialect (such as the draft's requirement that all methods be virtual) were ignored.

The Delphi language has continued to evolve over the years to support constructs such as dynamic arrays, generics and anonymous methods. The old object syntax introduced by Apple ("Old-Style Object Types") is still supported. [3]

Versions

Compilers

Object Pascal compilers are available for a wide range of operating systems and architectures.

Legacy products

Interpreters

Pascal Script (formerly InnerFuse) and DWScript (Delphi Web Script) are open-source Object Pascal interpreters and scripting engines written in Delphi. They support subsets of Object Pascal. DWScript can also compile Object Pascal code into JavaScript code (Smart Pascal), and supports just-in-time compilation (JIT). Modern Pascal provides 3 different interpreters: a command-line interface (CLI), Apache Module (Celerity), and CodeRunner (node.js like solution able to handle different scripts per port), besides the ability to compile and protect a script's source code. [9]

Sample "Hello World" programs

Here are several "Hello World" programs in different Object Pascal versions.

Apple version

programObjectPascalExample;typeTHelloWorld=objectprocedurePut;end;varHelloWorld:THelloWorld;procedureTHelloWorld.Put;beginShowMessage('Hello, World!');end;beginNew(HelloWorld);HelloWorld.Put;Dispose(HelloWorld);end.

Turbo Pascal version

Still supported in Delphi and Free Pascal. FPC also packages its own substitutes for the libraries/units. Delphi doesn't. The Free Pascal 1.0 series and the FPC textmode IDE are the largest open codebases in this dialect. Free Pascal 2.0 was rewritten in a more Delphi-like dialect, and the textmode IDE and related frameworks (Free Vision) are the only parts in the TP version of Object Pascal.

Stack based allocation

programObjectPascalExample;typeTHelloWorld=objectprocedurePut;end;procedureTHelloWorld.Put;beginWriteLn('Hello, World!');end;varHelloWorld:THelloWorld;{ allocated on the stack and can be used without explicit allocation. }beginHelloWorld.Put;end.

Heap based allocation

programObjectPascalExample;typePHelloWorld=^THelloWorld;THelloWorld=objectprocedurePut;end;procedureTHelloWorld.Put;beginWriteLn('Hello, World!');end;varHelloWorld:PHelloWorld;{ this is a typed pointer to a THelloWorld }beginNew(HelloWorld);HelloWorld^.Put;Dispose(HelloWorld);end.

Another example:

programObjectPascalExample;typePHelloWorld=^THelloWorld;THelloWorld=objectprocedurePut;end;procedureTHelloWorld.Put;beginWriteLn('Hello, World!');end;varHelloWorld:PHelloWorld;{ this is a typed pointer to a THelloWorld }HelloWorld2:^THelloWorld;{ this is exactly the same with different syntax }HelloWorld3:^THelloWorld;HelloWorld4:PHelloWorld;begin{ This works in a similar way as the code above, note the allocation and de-allocation, though,     many people get confused. In the past there was a wrong example with wrong comments here... }New(HelloWorld);{ one instance }HelloWorld4:=HelloWorld;{ this is valid - a pointer copy }HelloWorld2:=HelloWorld;{ this is valid - a pointer copy }New(HelloWorld3);{ a second instance }HelloWorld4:=HelloWorld3;{ this is valid - a pointer copy }HelloWorld2:=HelloWorld3;{ this is valid - a pointer copy }Dispose(HelloWorld);{ it allocates only two instances }Dispose(HelloWorld3);{ so it must release only two instances }end.

This works based on pointer copy, unless there is a specific allocation for a deeper copy.

Delphi and Free Pascal version

programObjectPascalExample;typeTHelloWorld=classprocedurePut;end;procedureTHelloWorld.Put;beginWriteln('Hello, World!');end;varHelloWorld:THelloWorld;{ this is an implicit pointer }beginHelloWorld:=THelloWorld.Create;{ constructor returns a pointer to an object of type THelloWorld }HelloWorld.Put;HelloWorld.Free;{ this line deallocates the THelloWorld object pointed to by HelloWorld }end.

Note that the object construct is still available in Delphi and Free Pascal.

Modern Pascal version

programObjectPascalExample;typeTHelloWorld=classPut:procedureofobject;end;procedureTHelloWorld.Put;beginWriteln('Hello, World!');end;procedureTHelloWorld.Free;begin// dispose any pointers //end;procedureTHelloWorld.Init;begin// initialize variables// link methods (manual RTTI)withSelfdobeginTMethod(@Put):=[@THelloWorld.Put,@Self];TMethod(@Free):=[@THelloWorld.Free,@Self];End;end;varHelloWorld:THelloWorld;{ this is an implicit pointer }beginHelloWorld.Init;{ self initialization (pointer to an object) of type THelloWorld }HelloWorld.Put;HelloWorld.Free;{ this line deallocates the THelloWorld object pointed to by HelloWorld }end.

Oxygene version

namespaceObjectPascalExample;interfacetypeConsoleApp=classclassmethodMain;end;THelloWorld=classmethodPut;end;implementationmethodTHelloWorld.Put;beginConsole.WriteLine('Hello, World!');end;classmethodConsoleApp.Main;beginvarHelloWorld:=newTHelloWorld;HelloWorld.Put;end;end.

DWScript (Smart Pascal) version

typeTHelloWorld=classprocedurePut;beginPrintLn('Hello, World!');endend;varHelloWorld:=THelloWorld.Create;HelloWorld.Put;

The method implementation can also be made in a distinct location as in other Object Pascal dialects.

Development

Many features have been introduced continuously to Object Pascal with extensions to Delphi and extensions to FreePascal. In reaction to criticism, Free Pascal has adopted generics with the same syntax as Delphi, provided Delphi compatibility mode is selected, and both Delphi (partial) and Free Pascal (more extensive) support operator overloading. Delphi has also introduced many other features since version 7, [10] including generics. Whereas FreePascal tries to be compatible to Delphi in Delphi compatibility mode, it also usually introduced many new features to the language that are not always available in Delphi.

Related Research Articles

Pascal (programming language) Programming language

Pascal is an imperative and procedural programming language, designed by Niklaus Wirth as a small, efficient language intended to encourage good programming practices using structured programming and data structuring. It is named in honour of the French mathematician, philosopher and physicist Blaise Pascal.

Turbo Pascal is a software development system that includes a compiler and an integrated development environment (IDE) for the Pascal programming language running on CP/M, CP/M-86, and DOS. It was originally developed by Anders Hejlsberg at Borland, and was notable for its extremely fast compiling times. Turbo Pascal, and the later but similar Turbo C, made Borland a leader in PC-based development.

Anders Hejlsberg Danish software engineer (born 1960)

Anders Hejlsberg is a Danish software engineer who co-designed several programming languages and development tools. He was the original author of Turbo Pascal and the chief architect of Delphi. He currently works for Microsoft as the lead architect of C# and core developer on TypeScript.

C++Builder is a rapid application development (RAD) environment, originally developed by Borland and as of 2009 owned by Embarcadero Technologies, for writing programs in the C++ programming language currently targeting Windows, iOS and for several releases, macOS and Android C++Builder combines the Visual Component Library and IDE written in Object Pascal with multiple C++ compilers. Most components developed in Delphi can be used in C++Builder with no or little modification, although the reverse is not true, but this constraint is valid only for source code. Binary code generated by Delphi can easily be linked to binary code generated by C++Builder and vice versa to generate an executable written in both Object Pascal and C++. With this approach, C++ can be called from Object Pascal and vice versa. Since both Delphi and C++ use the same back end linker, the debugger can single step from Delphi code into C++ transparently.

The Visual Component Library (VCL) is a visual component-based object-oriented framework for developing the user interface of Microsoft Windows applications. It is written in Object Pascal.

Delphi (software)

Delphi is a software product that uses the Delphi dialect of the Object Pascal programming language and provides an integrated development environment (IDE) for rapid application development of desktop, mobile, web, and console software, currently developed and maintained by Embarcadero Technologies.

Free Pascal Free compiler and IDE for Pascal and ObjectPascal

Free Pascal Compiler (FPC) is a compiler for the closely related programming-language dialects Pascal and Object Pascal. It is free software released under the GNU General Public License, with exception clauses that allow static linking against its runtime libraries and packages for any purpose in combination with any other software license.

Borland Kylix is a compiler and integrated development environment (IDE) formerly sold by Borland, but later discontinued. It is a Linux software development environment based on Borland Delphi and Borland C++ Builder, which runs under Microsoft Windows. Continuing Delphi's classical Greek theme, Kylix is the name for an ancient Greek drinking cup. The closest supported equivalent to Kylix is the free Lazarus IDE package, designed to be code-compatible with Delphi. As of 2010 the project has been resurrected in the form of Delphi cross compiler for Mac and Linux, as shown in the Embarcadero's Delphi and C++ Builder roadmap. As of September 2011 with Kylix discontinued the framework for cross-platform development by Embarcadero is FireMonkey.

Virtual Pascal is a free 32-bit Pascal compiler, IDE, and debugger for OS/2 and Microsoft Windows, with some limited Linux support. Virtual Pascal was developed by Vitaly Miryanov and later maintained by Allan Mertner.

In computer programming, an entry point is where the execution of instructions of a program begins, and where the program has access to command line arguments.

Lazarus (software)

Lazarus is a free cross-platform visual integrated development environment (IDE) for rapid application development (RAD) using the Free Pascal compiler. Its goal is to provide an easy-to-use development environment for programmers developing with the Object Pascal language, which is as close as possible to Delphi.

The Visual Component Framework (VCF) is an abandoned open source project for development under Microsoft Windows and Apple Macintosh that is distributed under the BSD license. It is an advanced C++ application framework that makes it easier to produce GUI-based C++ applications. The framework is C++ design and has built in support for rapid application development. The framework is designed to be portable over multiple platforms and compilers.

Oxygene (programming language)

Oxygene is a programming language developed by RemObjects Software for Microsoft's Common Language Infrastructure, the Java Platform and Cocoa. Oxygene based on Delphi's Object Pascal, but also has influences from C#, Eiffel, Java, F# and other languages.

Borland C++ is a C and C++ IDE for MS-DOS and Microsoft Windows. It was the successor to Turbo C++, and included a better debugger, the Turbo Debugger, which was written in protected mode DOS.

Turbo51

Turbo51 is a compiler for the programming language Pascal, for the Intel MCS-51 (8051) family of microcontrollers. It features Borland Turbo Pascal 7 syntax, support for inline assembly code, source-level debugging, and optimizations, among others. The compiler is written in Object Pascal and produced with Delphi.

RemObjects Software is an American software company founded in 2002 by Alessandro Federici and Marc Hoffman. It develops and offers tools and libraries for software developers on a variety of development platforms, including Embarcadero Delphi, Microsoft .NET, Mono, and Apple's Xcode.

Smart Pascal is a dialect of the Object Pascal computer language that is derived from Delphi Web Script, but is enhanced and adapted for Smart Mobile Studio, a commercial development suite that generates JavaScript rather than machine code.

Modern Pascal is a closed source, cross-platform, interpreter, compiler, and runtime system (environment) for command line, server-side and networking applications. Modern Pascal applications are written in Pascal and Object Pascal, and can be run within the Modern Pascal runtime on the operating systems Microsoft Windows, Linux, macOS, FreeBSD, Solaris and DOS/32. Its work is hosted and supported by the 3F, LLC and partner MP Solutions, LLC.

Delphi is a software product that uses the Object Pascal programming language and provides an integrated development environment (IDE) for rapid application development of desktop, mobile, web, and console software, currently developed and maintained by Embarcadero Technologies. Delphi evolved from Borland's "Turbo Pascal for Windows", itself an evolution with Windows support from Borland's Turbo Pascal and Borland Pascal with Objects, very fast 16-bit native-code MS-DOS compilers with their own sophisticated integrated development environment (IDE) and textual user interface toolkit for DOS. Early Turbo Pascal was written in a dialect of the Pascal programming language; in later versions support for objects was added, and it was named Object Pascal.

References

  1. 1 2 Gibson, Steve (May 8, 1989). "Borland and Microsoft Enter the Object-Oriented Pascal Ring". InfoWorld . p. 28.
  2. Tesler, Larry (1985). "Object Pascal Report". Structured Language World. 9 (3): 10–7.
  3. Lischner, Ray (2000). Delphi in a nutshell: a desktop quick reference (1st ed.). Sebastopol, CA: O'Reilly and Associates. ISBN   1565926595.
  4. Community Letter: Embarcadero Technologies agrees to acquire CodeGear from Borland. Edn.embarcadero.com. Retrieved on 2013-07-21.
  5. "iPhone/iPod development". Free Pascal development team. Retrieved 2009-04-13.
  6. "A Smart Book".
  7. Funa, Igor (2021). "Turbo51: Turbo Pascal Compiler for 8051 microcontrollers". Archived from the original on 2018-09-25.
  8. Draxler, Wolfgang. "WDSibyl: Visual Development Environment". Archived from the original on 2020-02-12.
  9. "Modern Pascal".
  10. "New Delphi language features since Delphi 7". CodeGear. Retrieved 2008-07-06.

Delphi