Loading AI tools
Branch of object-oriented derivatives of Pascal programming language From Wikipedia, the free encyclopedia
Object Pascal is an extension to the programming language Pascal that provides object-oriented programming (OOP) features such as classes and methods.
This article needs additional citations for verification. (May 2019) |
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 appeared | 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, PascalABC.NET, Oxygene | |
Influenced by | |
Pascal, Simula, Smalltalk | |
Influenced | |
C#, Genie, Java, Nim, C/AL |
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 created by Anders Hejlsberg. 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 which included Hejlsberg's C#.
Pascal became a major language in the programming world in the 1970s, with high-quality implementations on most minicomputer platforms and microcomputers. Among the latter 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.
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.[3] 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, had already been rewritten in C++ and ported to this platform.
Metrowerks offered with CodeWarrior an Object Pascal compiler for Macintosh that targeted both 68k and PowerPC, both in their IDE and as MPW tools. Macintosh developers using Object Pascal had a path to port to the PowerPC, even architecture after both Apple and Symantec dropped support. MacApp 2.0, written in Object Pascal, was ported to the PowerPC using CodeWarrior.[4][5]
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.[6]
asm
sections which are plain JavaScript but have access to Pascal symbols, or external classes which map directly to prototypal JavaScript classes. Smart Pascal introduces true inheritance, classes, partial classes, interfaces, a virtual method table and many other advanced constructs which are not a part of JavaScript by default.Object Pascal compilers are available for a wide range of operating systems and architectures.
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.[15]
Here are several "Hello World" programs in different Object Pascal versions.
program ObjectPascalExample;
type
THelloWorld = object
procedure Put;
end;
var
HelloWorld: THelloWorld;
procedure THelloWorld.Put;
begin
ShowMessage('Hello, World!');
end;
begin
New(HelloWorld);
HelloWorld.Put;
Dispose(HelloWorld);
end.
Still supported in Delphi and Free Pascal. FPC also packages its own substitutes for the libraries/units. Delphi does not. 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.
program ObjectPascalExample;
type
THelloWorld = object
procedure Put;
end;
procedure THelloWorld.Put;
begin
WriteLn('Hello, World!');
end;
var
HelloWorld: THelloWorld; { allocated on the stack and can be used without explicit allocation. }
begin
HelloWorld.Put;
end.
program ObjectPascalExample;
type
PHelloWorld = ^THelloWorld;
THelloWorld = object
procedure Put;
end;
procedure THelloWorld.Put;
begin
WriteLn('Hello, World!');
end;
var
HelloWorld: PHelloWorld; { this is a typed pointer to a THelloWorld }
begin
New(HelloWorld);
HelloWorld^.Put;
Dispose(HelloWorld);
end.
Another example:
program ObjectPascalExample;
type
PHelloWorld = ^THelloWorld;
THelloWorld = object
procedure Put;
end;
procedure THelloWorld.Put;
begin
WriteLn('Hello, World!');
end;
var
HelloWorld: 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.
program ObjectPascalExample;
type
THelloWorld = class
procedure Put;
end;
procedure THelloWorld.Put;
begin
Writeln('Hello, World!');
end;
var
HelloWorld: THelloWorld; { this is an implicit pointer }
begin
HelloWorld := 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.
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.
type
THelloWorld = class
procedure Put;
begin
PrintLn('Hello, World!');
end
end;
var HelloWorld := THelloWorld.Create;
HelloWorld.Put;
The method implementation can also be made in a distinct location as in other Object Pascal dialects.
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,[16] 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.
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.