tags:

views:

231

answers:

3

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?

+8  A: 

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
very, very bad move, indeed :(
migajek
`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
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
+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
Oh well, instead of C# and Java why not C++?
ldsandon
@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
+11  A: 

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
You are correct, `TObjectList` didn't exist in Delphi 1.
Nat
... 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
A: 

My intention is to get a good grounding in OP before moving on to newer versions. While Delphi 1 is lacking in a few things it fits what I need right now. Once I have a solid foundation I'll look at a newer version (though the prices are killer).

One advantage to an older version is lots of features aren't available to me - this forces me to solve a problem with code alone.

Thanks to everyone who weighed in on this. I want to accept Masons reply as the answer but I don't see how. The outlined checkmarks aren't visible to me. I also can't edit my question. Maybe it's time to get an OpenID?

Thanks again,

Frank_M

Frank_M
Something happened to your account, as to us reading appear there are 2 Frank_M (the one with 46 reputation plus a bronze badge and other with 1 reputation)
Fabricio Araujo