Records in Delphi

In Delphi, you still have the old pascal method of creating records to hold data and then create pointers to get to this data. The problem with this approach is that it is not really object oriented. You have to cleanup the records behind the pointers. There is no way Delphi can do this for you. A better approach is to use TCollection and TCollectionItem descendants. An extra advantage, next to this automagical disposal is that you create methods on the ColectionItem that do special things, related to the data. I built ANT using pointers to records. When a user clicks on a button to start an application, I needed to find the record related to this button. Then I had to take the data from this record and send this into a method to start the application. In ANT 2.0 I can create a method on the collectionitem that does this for me. I still have to write the code to start the application, but I will┬ánot have to rewrite my ‘search’ method.

Come to think of it, maybe I can even store the image/glyph used to display on the button in this collectionitem. That way I will not need an imagelist. Hmm… nice idea…

One thought on “Records in Delphi

  1. Nice tip!! This one is not mentioned often in de books on Delphi. They usually talk about records, but this one is much more powerful.


Leave a Reply

Your email address will not be published. Required fields are marked *