| RTL referenceGlossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link To |
| Creating Custom Delphi Components - Inside and Out | ||||||||||||||||||
| Page 6: On Destructors and Methods | ||||||||||||||||||
Destructors As with the standard Create constructor, every object gets a default destructor from TObject, called "Destroy". Call this when you're finished with an object to do any cleaning up necessary, like this:
You can also use "SomeObject.Free", which is a wrapper for the Destroy destructor but with a check: "if Self <> nil then Destroy;" This is safer, so I recommend you use "Free" instead. I'll discuss 'Self' later.
So how do you put destructors into your classes? Well, here's a simple example:
This code should give you a warm sense of familiarity, as it's almost the same as the constructor code. There's only one difference - "override". This is because the standard Destroy destructor is declared as Virtual. I'll talk about Virtual methods later on in this tutorial, so don't worry - it's just to do with inheritance and (scary big word alert!) "polymorphism".
Well, most of the same points for constructors apply to destructors. Again, you can have many destructors with different names, and again it's probably not a wise move. There's not really much to go over, then, is there? Let's go on to the next topic...
Methods
That code should not scare you in the slightest. You've been doing similar things with your forms. If you look in your form's code, you might spot the bit "TSomeForm = class(TForm)". Hopefully you now understand what's going on - each time you use a form, it gets inherited from TForm, and you customise it as appropriate, which is the standard inheritance concept.
When you write methods for you classes, the only thing to remember is that they have the class name followed by a period (dot) before the name - like "TGeneric.Whatever". Other than that, they're completely straightforward. The only thing you need to be aware of, "Self", will be talked about in the next section, namely...
Question, Suggestions... |
||||||||||||||||||
All graphics (if any) in this feature created by Zarko Gajic.
| More Delphi |
|
· Learn another routine every day - RTL Quick Reference. · Download free source code applications and components. · Talk about Delphi Programming, real time. · Link to the Delphi Programming site from your Web pages. · Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC. |
|
· NEXT ARTICLE:
GDI Graphics In Delphi. From simple lines to direct API calls: the ultimate tutorial to GDI graphics in Delphi. This tutorial will introduce you to some of the techniques in the GDI Delphi drawing. Look for: drawing lines and shapes, drawing pictures, flicker-free drawings, off-screen bitmaps, GDI drawings the API way... |
| Stay informed with all new and interesting things about Delphi (for free). |
|
|
| Got some code to share? Got a question? Need some help? |

