Jump to content

Object Pascal

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 67.76.228.3 (talk) at 12:11, 16 September 2006. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Object Pascal is an object oriented derivative of Pascal mostly known as the primary programming language of Borland Delphi. It is also known as the "Delphi programming language" when describing the dialect used by Borland Delphi.

Borland used the name "Object Pascal" for the programming language in the first versions of Borland Delphi, but later renamed it to the "Delphi programming language". However, compilers that claim to be Object Pascal compatible, are often trying to be compatible with Delphi source code.

Borland sells integrated development environments (IDEs) that compile the Delphi programming language to Microsoft Windows, the Microsoft .NET Framework and Linux. The open source Free Pascal project allows the language to be compiled for Mac OS X, Win64 and Windows CE.

Early history at Apple

Object Pascal was a creation of Niklaus Wirth and Larry Tesler. It was created at Apple Computer in early 1985 through their collaboration. It added object-oriented extensions to the existing Pascal programming language.

Object Pascal was needed in order to allow the creation of MacApp, an expandable Macintosh application framework that would now be called a class library. Object Pascal extensions and MacApp itself were done by Barry Hanes, Ken Doyle, Larry Rosenstein, and tested by Dan Allen. Larry Tesler oversaw the project which began in very early 1985 and became a product in 1986.

Apple dropped support for Object Pascal when they moved from Motorola 68K chips to IBM's PowerPC architecture in 1994.

The Borland years

Delphi Version 3 Unser Manual.
Delphi Version 3 Unser Manual.

In 1986, Borland introduced similar extensions, also called 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, called Delphi and introduced a new set of extensions to create what is now known as the Delphi language. It featured an incompatible 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 obviously inspired by the ISO working draft for object-oriented extensions, but many of the differences to Turbo Pascal's dialect (such as the draft's requirement that all methods be virtual) were ignored. The Delphi language continued to evolve throughout the years to support new language concepts such as 64-bit integers and dynamic arrays.

Compilers

There are a number of compilers that are more or less compatible with the Object Pascal language from Delphi. Many of these exist because they enable the use of Object Pascal source code on specific platforms or have specific licenses.

  • Borland Delphi is probably the best known compiler. It targets Win16, Win32 and .net.
  • Borland Kylix is a Linux variant of Delphi, and only targets Intel 32-bit Linux using Qt.
  • Free Pascal A commandline compiler that aims source compatibility with the core feature set of both the Turbo Pascal and Delphi dialects. The current version is 2.0(.2), which are highly Delphi6/7 compatible. Operates on most x86 operating systems. Supports Linux, Mac OS and Mac OS X (including an Xcode implementation) on PowerPC family, and Linux on AMD64. SPARC and Acorn RISC Machine (ARM) architectures are working and formally released but not 100% end-user ready yet.
  • GNU Pascal (Separately distributed part of the GNU Compiler Collection) While formally not aimed at the Borland dialects of Pascal, it does contain a Borland Pascal compatibility mode, and is very slowly absorbing Delphi language features, though not yet directly suitable for recompiling large bodies of Delphi code. It is the most prolific compiler in terms of operating systems and processors though, and therefore deserves mentioning as a last resort.
  • InnerFuse is a Delphi interpreter for embedding in applications. It is rumoured to work with several of the alternatives too.
  • Virtual Pascal is a x86 32-bit Turbo Pascal and Delphi compatible compiler mainly aimed at OS/2 and Windows, though it developed a DOS+Extender and an experimental Linux cross-compiler too. The compiler is stuck on the level of about Delphi V2, and the site hasn't changed significantly in two years, and development of Virtual Pascal has stopped. Nevertheless, of the free alternatives, it is still the one with the best polished IDE and debugger though Free Pascal is getting nearer and nearer.
  • Chrome programming language. Chrome is an Object Pascal plug-in compiler for Visual Studio and as a native .NET/Mono command-line compiler. Target .NET and Mono platforms. Newest of the compiler options.

Hello world example

Apple's Object Pascal

 program ObjectPascalExample;
type THelloWorld = object procedure Put; end;
var HelloWorld: THelloWorld;
procedure THelloWorld.Put; begin WriteLn('Hello, World!'); end;
begin New(HelloWorld); HelloWorld.Put; Dispose(HelloWorld); end.

Turbo Pascal's Object Pascal

 program ObjectPascalExample;
type PHelloWorld = ^THelloWorld; THelloWorld = object procedure Put; end;
var HelloWorld: PHelloWorld;
procedure THelloWorld.Put; begin WriteLn('Hello, World!'); end;
begin New(HelloWorld); HelloWorld^.Put; Dispose(HelloWorld); end.

Delphi's Object Pascal

 program ObjectPascalExample;
type THelloWorld = class procedure Put; end;
var HelloWorld: THelloWorld;
procedure THelloWorld.Put; begin WriteLn('Hello, World!'); end;
begin HelloWorld := THelloWorld.Create; HelloWorld.Put; HelloWorld.Free; end.

Chrome's Object Pascal

-> Chrome programming language

 namespace ObjectPascalExample;
interface
type ConsoleApp = class class method Main; end;
THelloWorld = class method Put; end;
implementation
method THelloWorld.Put; begin Console.WriteLine('Hello, World!'); end;
class method ConsoleApp.Main; begin var HelloWorld := new THelloWorld; HelloWorld.Put; end;
end.

See also

Delphi's Object Pascal Language guide:

Free Pascal Object Pascal reference guide:

GNU Pascal(GPC) information