Hacker News new | ask | show | jobs
by pjmlp 3066 days ago
You used Delphi, not Object Pascal.

Object Pascal was created by Apple for Lisa and Mac OS, with collaboration from Niklaus Wirth.

Borland then adopted it to Turbo Pascal 5.5 for MS-DOS.

Turbo Pascal 6.0 and 7.0 for MS-DOS, followed by Turbo Pascal 1.0 and 1.5 for Windows 3.x took up ideas from C++.

Borland then rebooted Turbo Pascal with Delphi, but to avoid creating too much confusion among Pascal developers, they kept calling their dialect Object Pascal, even though they completly rebooted the object model.

This is how you declare objects in Object Pascal.

    type
        PTPoint = ^TPoint;
        TPoint = object
           x: Integer;
           y: Integer;
        end;
        
    var
      valuePointOnGlobalMemory: TPoint;
      valuePointOnTheHeap: PTPoint;

    begin
      {Can use it right away}
      valuePointOnGlobalMemory.x := 10;
      valuePointOnGlobalMemory.y := 20;
      
      {Need to heap allocate first}
      New(valuePointOnTheHeap);
      valuePointOnTheHeap^.x := 10;
      valuePointOnTheHeap^.y := 20;
      Dispose(valuePointOnTheHeap);
      
      {....}
    end.
Easy to test with Free Pascal using Turbo Pascal compatibility mode.
1 comments

Nitpick: Borland didn't reboot the object model, they extended it to add the 'class' types, but the 'object' types remained unchanged. The code you wrote works in both Delphi and Free Pascal :-). Object types are used often when you want to allocate objects on the stack or when you want to "embed" objects in other objects/classes (i don't know about Delphi but Free Pascal also extends object types to support newer stuff like properties).
Thanks for the correction, always welcome.

Delphi 1.0 was about the time I started focusing on C++, so I am not that knowledgeable about its features. Just remembered that was one of the key changes.