gettingstarted
[Top] [All Lists]

Re: [RB List] NilObjectException?

To: Getting Started <gettingstarted at lists dot realsoftware dot com>
Subject: Re: [RB List] NilObjectException?
From: Stuart Malin <stuart at ossayu dot com>
Date: Tue, 22 Feb 2005 18:14:03 -0500
Delivered-to: gettingstarted at lists dot realsoftware dot com
References: <20050222221224 dot 2C14074C148 at lists dot realsoftware dot com> <d99853c08702b7f9d540bbb325d7bb9f at ossayu dot com> <421BB77B dot 63073CB4 at online dot no>

On Feb 22, 2005, at 5:51 PM, Eirik Karlsen wrote:

Did a quick websearch for 'constructor', found little useful info.

So what kinda animal is a "constructor" and what does it do?

A "constructor" is a method (subroutine) that runs for an object when it is being created, without any of your code having to call it.

If you create a new Class, you can create a subroutine named Constructor for it.

This subroutine will be invoked when a new object of that class is created.

For instance, if you have a class named Class1 with a Constructor method, then when this code is executed:

        dim obj as new Class1

The Constructor for that class will run. If Class1 has properties that need to be initialized for each new object, then the code to do such initialization is best put in the Constructor. That way, the initialization happens automatically, and you don't have to remember to do something like the following everywhere that you instantiate a new object of Class1.

        dim obj as new Class1
        obj.initialize

You can define a Constructor for controls in windows (if you sub class the control class). But I'd stay away from this, as the timing of the various code points is subtle. For controls, I recommend that you stick to the Open event handler.

On the other hand, a Constructor can be quite useful in many other classes. Say, for instance, you've got a linked list. When you create an object that belongs linked to the list, the object can be hooked in by the Constructor method.

HTH,
Stuart

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>