Modern Object Pascal Introduction: units, classes, generics, memory management, exceptions and more.

203 points•birdculture•7 days ago•89 comments•

89 comments

tombert4 days ago
When I was first learning to program, I started using the free Borland Turbo C++ compiler [1]. I had managed to get subscribed to their newsletter that seemed very insistent that Delphi was going to be the future for desktop software. Awhile later, I found out that "Spybot – Search & Destroy" was written in Delphi, so I figured it might be fun to play with.

So play with it I did. I hadn't used Visual Basic at the time, so the entire idea of "drag and drop" GUIs was kind of amazing, and I even kind of ended up liking the language.

I wasn't able to get any kind of OpenGL stuff working with it, so I ended up going back to C and I really haven't touched the language since, but I kind of feel like I should at some point just to finish off that loose thread in my education.

[1] I actually don't remember if that was proper freeware or if I had gotten it cough unofficially free...

alwillis4 days ago
Photoshop 1.0 was written mostly in Object Pascal with some 68000 assembly language; source code is available:

https://computerhistory.org/blog/adobe-photoshop-source-code...

WillAdams5 days ago
I bought Delphi ages ago, but never got very far with it, which I regret.

I'd love to be able to take it up again, and this document looks very promising for that, esp. paired with:

https://wiki.freepascal.org/pas2js

which I now see is supported in Lazarus.

If someone has an example graphical project which compiles to an HTML page w/ JavaScript using the above, I'd love to see it and a detailed set of build instructions and notes on installing the needed toolchain and deployment. (as a note, I'm currently working in flet.dev using Python which allowed me to get a small prototype up-and-running, but I'm still looking into self-hosting and doing something more complex)

armcat4 days ago
This takes me back, my first adventure in programming was as a 12 year old creating a Pong clone using Turbo Pascal on DOS. It came in handy later as a 20 year old when I was doing freelance as a Delphi dev. Amazing to see Pascal on HN.
jasonwatkinspdx4 days ago
At around the same age I learned a version/imitation of Object Pascal for scripting the PIRCH IRC client on windows 95. It was neet when a friends dad who was a professional programmer showed me the latest version of Delphi, which he was pretty excited about, and I could actually understand most of what he was showing me.
WillAdams4 days ago
The really interesting thing to me is when Modula 2/3 and Oberon come up --- I'd _really_ love to see a bare-metal implementation of Oberon for the Raspberry Pi which was:

- actually ported (_not_ emulated) w/ native drivers

- easy to install

- performant

- had an attractive GUI

- had a web browser which could handle the basics of the modern web

I mean, the documentation is sixteen pages --- seems like a perfect fit --- still waiting on a tablet shell for an rPi 5 (and still need to get an rPi 5 Compute Module for it), so will be looking into it then....

mikewarot4 days ago
One of the greatest features of FreePascal is that strings are managed. You never allocate or deallocate them, you just declare the variable, and it manages them. They're counted, reference counted, copy on write, and can hold gigabytes.

According to google:

When you assign one dynamic string to another, Free Pascal does not duplicate the actual characters in memory. Instead, both variables point to the same character buffer in the heap, and the runtime increments an internal reference counter. A physical memory copy is only triggered when one of the string instances is modified (written to)

Free Pascal strings are as close as you get to magic, compared to C/C++.

Panzerschrek4 days ago
COW-strings aren't free. In a multithreaded environment they require atomic operations for use counter, which isn't cheap. Some time ago some implementations of C++ did use COW-strings too, but this approach was rejected due to such performance concerns.
exceptione4 days ago
Many languages provide 2 primitives as we generally want 2 different concepts:

  String            -> immutable string
  StringBuilder     -> mutable string, optimized methods for string modification
pjmlp4 days ago
Most of those ideas were present in PL/I, but we all know how it went.
exceptione4 days ago

  > Free Pascal strings are as close as you get to magic, compared to C/C++.
Not your point of reference, but Java and C# treat strings as immutable objects too.
sixthDot3 days ago
> strings are managed

Actually all dynamic array are.

Read the full thread on Hacker News →

Related stories