Jump to content

Object Pascal

From Alfawiki
Object Pascal
Company typeProgramming language
IndustrySoftware development
PredecessorPascal, Clascal
Founded1985
FounderApple Computer, Niklaus Wirth
FateSuperseded by Delphi and other languages
Headquarters
United States
ProductsObject Pascal language, MacApp framework, Think Pascal compiler, Turbo Pascal extensions, Delphi IDE

Object Pascal represents an enhancement of the Pascal language, incorporating object-oriented programming (OOP) capabilities such as classes and methods.

Initially created by Apple Computer under the name Clascal for the Lisa Workshop, it was further developed into Object Pascal through collaboration with Niklaus Wirth, the original author of Pascal. In the mid-1980s, Object Pascal served as the main language for early editions of the MacApp application framework, but its use declined following the 1991 introduction of MacApp 3.0, which was based on C++; official support for Object Pascal concluded in 1996.

Symantec delivered a high-performance Object Pascal compiler within their Think Pascal product, surpassing Apple's own Macintosh Programmer's Workshop (MPW) in speed. Symantec also created the Think Class Library (TCL), inspired by MacApp principles and accessible from both Object Pascal and THINK C. During the late 1980s, the Think development environment became the leading platform for Macintosh software creation.

Symantec extended Object Pascal to PC environments, preserving its Pascal-centric libraries rather than transitioning TCL to C++ as eventually occurred.

Borland incorporated object-oriented programming features into Turbo Pascal version 5.5, paving the way for the Object Pascal dialect utilized in Delphi, designed by Anders Hejlsberg. Delphi remained a prominent tool for business application development on PCs well into the early 2000s before being partially supplanted by the .NET Framework, which introduced Hejlsberg's C#.

Apple Pascal

During the 1970s, Pascal established itself as a widely adopted programming language, with robust implementations across various minicomputer and microcomputer systems. One notable example was the UCSD Pascal environment, which compiled code into an intermediate p-System format that could operate on multiple platforms. Apple licensed UCSD Pascal as a foundation for their own Apple Pascal system tailored for the Apple II and Apple III computers.

Pascal held significant importance in this era. For the development of the Apple Lisa, it was selected as the primary programming language, this time compiled directly rather than interpreted via the p-System.

Clascal and Apple's early Object Pascal

At Apple Computer, a team led by Larry Tesler collaborated with Pascal's creator, Niklaus Wirth, to develop Object Pascal—an object-oriented extension of Pascal. This language evolved from an earlier variant called Clascal, which was employed on the Lisa computer.

Object Pascal provided support for Apple's expandable Macintosh application framework, MacApp—a class library designed to streamline application development. The language extensions and MacApp were crafted by Barry Haynes, Ken Doyle, and Larry Rosenstein, with Dan Allen conducting testing and Tesler managing overall direction. The initiative began in early 1985 and was officially released in 1986.

The Think Pascal integrated development environment also implemented Object Pascal. It featured a compiler, syntax-highlighted editor, debugger, and an accompanying class library. Many developers favored Think Pascal over Apple's implementation due to its quicker compile–link–debug cycles and superior tool integration. The final official release was version 4.01 in 1992; subsequently, Symantec issued an unofficial free release labeled 4.5d4.

When Apple transitioned from the Motorola 68000 series processors to IBM's PowerPC architecture in 1994, support for Object Pascal was discontinued. By that time, MacApp 3.0 had already been rewritten using C++ to accommodate this new platform.

Metrowerks included an Object Pascal compiler within their CodeWarrior suite targeting both 68k and PowerPC architectures through their IDE and MPW tools. This provided Macintosh developers with a migration route after Apple and Symantec ended their backing. Additionally, MacApp 2.0—originally written in Object Pascal—was ported to PowerPC using CodeWarrior.

Borland, Inprise, CodeGear, and Embarcadero era

In 1986, Borland expanded Turbo Pascal by adding Object Pascal extensions initially for Macintosh and subsequently for DOS. Shifting focus to Windows in 1994, Borland introduced Delphi, an evolution of Turbo Pascal featuring a revamped syntax along with additions like the class keyword, constructors, destructors, properties, and method pointers. The debut of Delphi 1.0 in 1995 marked the beginning of continuous language advancements, including capabilities such as dynamic arrays, generics, and anonymous methods.

Versions

  • Originally dubbed Object Pascal by Borland, the language was later renamed Delphi. Due to Delphi being a trademarked name, many compatible compilers prefer using Object Pascal.
  • After acquiring Delphi in 2008, Embarcadero Technologies has been distributing the Delphi integrated development environment (IDE), which compiles Object Pascal code for platforms including Windows, macOS, iOS, Android, and Web environments.
  • Delphi provided support for .NET from Delphi 8 through Delphi 2007; this was eventually supplanted by Oxygene, a language developed by RemObjects Software targeting the Common Language Infrastructure, Java Virtual Machine, and Apple's Cocoa frameworks.
  • The open source Free Pascal project offers cross-platform compilation across operating systems such as Linux, FreeBSD, macOS, and supports various hardware architectures. By 2009, Free Pascal extended its capabilities to include iPhone SDK development.
  • Designed for rapid application development targeting ECMAScript–JavaScript, the Smart Pascal language integrates closely with technologies like node.js and Embarcadero DataSnap. Created by Jon Lennart Aasenden and released by Optimale Systemer in 2012, it facilitates high-performance client-server web applications with advanced object-oriented features not present in standard JavaScript.
  • Morfik Pascal focuses on Ajax-based web applications through its AppsBuilder IDE, compiling Object Pascal into browser or server-side code using the Free Pascal compiler.
  • The open source GNU Pascal compiler supports ISO 7185 and ISO 10206 Extended Pascal standards within the GNU Compiler Collection framework.
  • Turbo51 is a free compiler tailored for programming Intel 8051 microcontrollers.
  • WDSibyl is an open source IDE and compiler resembling Delphi available on Microsoft Windows and OS/2. Initially a commercial product from Speedsoft, it evolved into a Delphi-style RAD environment before being released under the GPL license. Maintenance is currently handled by Wolfgang Draxler; however, its compiler DLL remains proprietary.

Compilers

Object Pascal compilers accommodate various operating systems and hardware platforms.

  • The most prominent compiler is Delphi, which evolved from Borland Pascal and Turbo Pascal. It targets platforms including Windows 9x (up to Delphi 2007), the Windows NT family, the .NET Framework (Delphi versions 8, 2005, 2007), macOS (from XE2 onward), native binaries for iOS (XE2+ with full native support starting XE4), and native binaries for Android (XE5+). Support for .NET was separated into Oxygene (see below).
  • The open-source Free Pascal Compiler (FPC) supports multiple Object Pascal dialects such as those of Turbo Pascal 7 and Delphi. It generates code for architectures including IA-32, x86-64, PowerPC, SPARC, and ARM, running on platforms like Microsoft Windows, Linux, FreeBSD, Classic Mac OS, and macOS with Xcode integration. The Lazarus IDE is a notable rapid application development environment built atop FPC.
  • Included in the GNU Compiler Collection, GNU Pascal provides compatibility with Turbo Pascal and limited support for Delphi features. Although not ideal for extensive Delphi projects, it supports a wide range of operating systems and hardware.
  • Developed by RemObjects Software, Oxygene integrates with Microsoft Visual Studio and is available as a free CLI compiler targeting the Common Language Infrastructure. It consists of three compilers aimed at different platforms: Echoes (.NET Framework, Mono, WinRT, Windows Phone 8), Cooper (JDK and Android), and Nougat (iOS and macOS).

Obsolete products

  • Borland Kylix represented a Linux adaptation of Delphi, designed for 32-bit Intel Linux systems using the Qt framework; however, it is incompatible with the majority of current Linux distributions.
  • Virtual Pascal was a no-cost 32-bit compiler compatible with Turbo Pascal and Delphi, primarily targeting OS/2 and Windows platforms. It later incorporated support for DOS+ Extender and experimental cross-compilation for Linux. Development halted once it reached feature parity with Delphi 2, and its website was discontinued in 2007.

Interpreters

Pascal Script (previously known as InnerFuse) and DWScript are open-source scripting engines and Object Pascal interpreters created using Delphi. Both implement subsets of Object Pascal; notably, DWScript can translate Object Pascal code into JavaScript (Smart Pascal) and includes just-in-time compilation (JIT) capabilities. Contemporary Pascal distributions provide three interpreter variants: a command-line interface (CLI), an Apache module called Celerity, and CodeRunner, which functions similarly to node.js by allowing multiple scripts to run on a single port. Additionally, these interpreters offer options for compiling script source code and protecting it.

Example "Hello World" programs

Presented below are several "Hello World" examples written in different dialects of Object Pascal.

Apple variant

<syntaxhighlight lang="objectpascal"> program ObjectPascalExample;

  type
     THelloWorld = object
        procedure Display;
     end;
  var
     HelloWorld: THelloWorld;
  procedure THelloWorld.Display;
  begin
     ShowMessage('Hello, World!');
  end;

begin

  New(HelloWorld);
  HelloWorld.Display;
  Dispose(HelloWorld);

end. </syntaxhighlight>

Turbo Pascal variant

Supported by both Delphi and Free Pascal, with Free Pascal providing its own replacements for libraries and units that Delphi lacks. Free Pascal 1.0 along with its text-mode IDE constitutes the largest open-source codebases in this dialect. Version 2.0 of Free Pascal was redesigned to more closely resemble Delphi; however, its text-mode IDE and Free Vision frameworks continue to operate within the Turbo Pascal style of Object Pascal.

Stack allocation example

<syntaxhighlight lang="objectpascal"> program ObjectPascalExample;

  type
     THelloWorld = object
        procedure Display;
     end;
  procedure THelloWorld.Display;
  begin
     WriteLn('Hello, World!');
  end;

var

 HelloWorld: THelloWorld; { allocated automatically on the stack }

begin

  HelloWorld.Display;

end. </syntaxhighlight>

Heap allocation example

<syntaxhighlight lang="objectpascal"> program ObjectPascalExample;

  type
     PHelloWorld = ^THelloWorld;
     THelloWorld = object
        procedure Display;
     end;
  procedure THelloWorld.Display;
  begin
     WriteLn('Hello, World!');
  end;

var

 HelloWorld: PHelloWorld; { pointer to THelloWorld }

begin

  New(HelloWorld);
  HelloWorld^.Display;
  Dispose(HelloWorld);

end. </syntaxhighlight>

Additional illustration:

<syntaxhighlight lang="objectpascal"> program ObjectPascalExample;

  type
     PHelloWorld = ^THelloWorld;
     THelloWorld = object
        procedure Display;
     end;
  procedure THelloWorld.Display;
  begin
     WriteLn('Hello, World!');
  end;

var

 HelloWorld, HelloWorld4: PHelloWorld;
 HelloWorld2, HelloWorld3: ^THelloWorld;

begin

  New(HelloWorld);           { first instance }
  HelloWorld4 := HelloWorld; { pointer assignment }
  HelloWorld2 := HelloWorld; { pointer assignment }
  New(HelloWorld3);          { second instance }
  HelloWorld4 := HelloWorld3;{ pointer reassignment }
  HelloWorld2 := HelloWorld3;{ pointer reassignment }
  Dispose(HelloWorld);       { free first instance }
  Dispose(HelloWorld3);      { free second instance }

end. </syntaxhighlight>

This method depends on copying pointers unless explicit deep copies are created.

Delphi and Free Pascal Edition

<syntaxhighlight lang="delphi"> program ObjectPascalExample;

type

 THelloWorld = class
   procedure Display;
 end;

procedure THelloWorld.Display; begin

 Writeln('Hello, World!');

end;

var

 HelloWorldInstance: THelloWorld;

begin

 HelloWorldInstance := THelloWorld.Create;
 HelloWorldInstance.Display;
 HelloWorldInstance.Free;

end. </syntaxhighlight> The object-oriented structure continues to be supported in both Delphi and Free Pascal environments.

Oxygene Edition

<syntaxhighlight lang="objectpascal"> namespace ObjectPascalExample;

interface

type

 ConsoleApp = class
   class method Main;
 end;
 THelloWorld = class
   method Display;
 end;

implementation

method THelloWorld.Display; begin

 Console.WriteLine('Hello, World!');

end;

class method ConsoleApp.Main; begin

 var HelloWorldInstance := new THelloWorld;
 HelloWorldInstance.Display;

end;

end. </syntaxhighlight>

DWScript (Smart Pascal) Edition

<syntaxhighlight lang="objectpascal"> type

 THelloWorld = class
   procedure Display;
   begin
     PrintLn('Hello, World!');
   end;
 end;

var HelloWorldInstance := THelloWorld.Create; HelloWorldInstance.Display; </syntaxhighlight>

As with other Object Pascal variants, method definitions can be separated from declarations.

Development

The Object Pascal language has progressively advanced, incorporating new features mainly through Delphi and Free Pascal. Addressing earlier critiques, Free Pascal implemented generics that align with Delphi's syntax when operating in compatibility mode. Both compilers support operator overloading, with Free Pascal providing a more extensive range of implementations. Since the release of Delphi 7, generics and other enhancements have been introduced. Although Free Pascal strives for compatibility with Delphi, it frequently integrates capabilities not present in Delphi itself.

External links

Delphi