Skip to content
Search

Object Pascal

lastmod 2025-12-10created 2025-12-104 edits

Object Pascal is a programming language developed by adding object-oriented concepts to Pascal. It is also widely known as the Delphi language.

It originated with the Object Pascal compiler developed for the Apple Lisa, the predecessor of the Apple Macintosh. The most widely known variant of Object Pascal is the "Delphi programming language" used in Borland/CodeGear's Delphi. Among products outside Borland/CodeGear, Free Pascal, which is developed as free software and closely resembles Delphi, also has nearly identical syntax.

Hello World

Apple's Object Pascal

program ObjectPascalExample;

   type
      THelloWorld = object
         procedure Put;
      end;

   var
      HelloWorld: THelloWorld;

   procedure THelloWorld.Put;
   begin
      WriteLn('Hello, World!');
      ReadLn;
   end;

begin
   New(HelloWorld);
   HelloWorld.Put;
   Dispose(HelloWorld);
end.

Turbo Pascal

program ObjectPascalExample;

   type
      PHelloWorld = ^THelloWorld;
      THelloWorld = object
         procedure Put;
      end;

   var
      HelloWorld: PHelloWorld; { this is a pointer to a THelloWorld }

   procedure THelloWorld.Put;
   begin
      WriteLn('Hello, World!');
   end;

begin
   New(HelloWorld);
   HelloWorld^.Put;
   Dispose(HelloWorld);
end.

Delphi Pascal

program ObjectPascalExample;
{$MODE DELPHI}  { Only for free pascal or compile option -Mdelphi }
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 }
  HelloWorld.Put;
  HelloWorld.Free;                       { this line dereferences the pointer }
end.

See also

Favorite site

author Zer0 sitemap