12

I'm using Delphi 1 16-bit to learn Pascal (don't laugh, it works fine, plus I can't afford a more recent version). I'm using a TList to hold object references for a simple address book. Each object is added to the TList like so:

DataList.Add(TAddrBookData.Create('Bob', '1 Mill St'));

Do I need to free the TAddrBookData objects myself? Or are they freed when TList.Free is run?

FrankCM
  • 207
  • 1
  • 7
  • Welcome to StackOverflow, Frank_M! Good question. I won't laugh, but I will warn you. 64-bit Windows is becoming more popular every day, and 16-bit apps won't run on it. If you can't afford a modern version, see if you can't at least find a used copy of Delphi 7 floating around somewhere. It's got a whole lot of enhancements over Delphi 1. – Mason Wheeler Jul 07 '10 at 12:31
  • Delphi 1 is not good start point to learn OOP. It is fine if you want to learn basics, but it is really outdated in terms of modern technologies. if you want to learn modern OOP and programming technologies i recommend C#, there is free IDE for it: http://www.microsoft.com/express/Downloads/#2010-Visual-CS. C# was designed by ex delphi architect, so it took all the best from it. – Andrey Jul 07 '10 at 12:36
  • 9
    if you however decide to learn Delphi, you might want to look for Delphi 7 Personal which was removed from Borland / CodeGear / Embarcadero websites, but still is available on some mirror hosters. I believe it is legal to use this as it was once published as freeware. – migajek Jul 07 '10 at 12:49
  • 4
    @Andrey: What he said is that he wanted to learn [Object] Pascal, not C# and not "OOP". Delphi 1 lacks a lot of modern features, it's true, but it will give him a good grounding in the basics, and learning to accomplish things without the newer features to lean on will make him a better programmer. (And it has a fine object model too. It's just not as refined as C# or modern Delphi editions.) But personally I think the most significant language enhancement he's missing out on is not the object model stuff, but long strings, which didn't exist in D1 IIRC. – Mason Wheeler Jul 07 '10 at 13:06
  • @Mason Wheeler it is pointless to learn Delphi 1 in these days. You should either learn classical Pascal (without OOP) or modern Delphi or C# or maybe c++. – Andrey Jul 07 '10 at 13:39
  • 2
    Delphi 1 is as much OOP as Delphi 2010 or VS 2010. For the matter, it could learn OOP using Turbo Pascal 6 or 7 as well. There's almost nothing new in Java or C# that wasn't already there, especially for a beginner learning the foundations. And maybe a less richer framework could help to focus on learning, instead of using pre-built classes. –  Jul 07 '10 at 15:35
  • +1 for using Delphi 1 - I still remember my first Windows application I have created in Delphi 1 by just writing Gauge1.Progress:= ScrollBar1.Position; in a ScrollBar1.OnChange event handler. I was astonished. Where was nothing like Delphi among the development tools at the time. – kludg Jul 08 '10 at 14:11
  • @migajek Delphi 7 was never freeware. – Alex Jul 09 '10 at 08:23
  • Alexander, I can agree, but still one could download it and use for free, with no time limitations. it had limited functionality and license that permitted only non-commercial usage, but still it was almost-freeware ;) – migajek Jul 09 '10 at 21:22

2 Answers2

12

You need to free them yourself. Later versions come with a TObjectList, which is like a TList except it will only accept objects and it has the option to take ownership and free them for you automatically when the list is freed. But I don't believe TObjectList existed in Delphi 1, so you'll have to take care of it manually.

Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
  • 4
    ... which is a fantastic *learning* opportunity... taking a TList and then designing an extension (derived class) to provide a TObject type-safe container with content ownership semantics. You will learn far more by *developing* such a class than you will be simply using one already provided. – Deltics Jul 07 '10 at 21:07
8

You will need to free (or FreeAndNil) those as well.

If you want to learn Object Pascal (Delphi) with a newer (and free) IDE try Lazarus as the free Turbo Delphi 2006 has been discontinued (what a bad move).

AlexV
  • 22,658
  • 18
  • 85
  • 122
  • 5
    very, very bad move, indeed :( – migajek Jul 07 '10 at 12:50
  • `FreeAndNil()` didn't exist in Delphi 1 (I know, I still have to use it maintain 16 bit code). But you can write your own. – Nat Jul 07 '10 at 12:54
  • Not too hard to implement indeed :) Delphi 1 is seems so far away... I have a sealed box of Delphi 1 at home that I keep as collector hehehe. – AlexV Jul 07 '10 at 13:21
  • 2
    +1 for the Lazarus tip. I have to say that it is very sad that there is no way of learning Delphi without paying for the official IDE. There are a few people that go to great lengths to learn Delphi (like the poster who had an old 16-bit copy lying around or maybe it bought for a little money), but the majority just leaves it. Who is going to pay a few hundred euro's just to fool around in the most basic version? I would take Visual Studio C# Express or Eclipse/Netbeans for Java and leave Delphi for what it is. – The_Fox Jul 07 '10 at 14:23
  • Oh well, instead of C# and Java why not C++? –  Jul 07 '10 at 15:37
  • @ldsandon: Quite a good idea, C++ is a good school. For Object Pascal, I have to agree with The_Fox... It's very sad. – Fabricio Araujo Jul 07 '10 at 20:09