Board index » delphi » Constructors and Destructors in Automation objects

Constructors and Destructors in Automation objects

Is it possible to have a constructor and destructor in an Automation object?
I need my server to keep track of how many objects are created by outside
clients. In a Visual Basic version I did this by incrementing or
decrementing in the Class_Initialize and Class_Terminate events that occur
whenever an object is created. I thought this would be even easier in
Delphi. I could just give the class of the object a constructor and
destructor and count there. Unfortunately this doesn't work and I don't see
an alternative.

When I try to create a constructor that overrides the default constructor
inherited from TAutoObject, I get an error saying that you can't override a
static method. I tried creating the constructor anyway without override.
Delphi lets me do this, but it doesn't seem to generate any code for the
constructor. The code I put in the constructor is never executed.

If there can be no constructor in an Automation class, does anybody know of
any other way for the server to monitor how many objects have been created?
Specifically I need to know when there are no remaining objects.

Bruce McKinney

 

Re:Constructors and Destructors in Automation objects


Quote
In article <65n76d$1jv2@forums>, Bruce McKinney wrote:
> Specifically I need to know when there are no remaining objects.

ComServ.ComServer.ObjectCount is the number of active objects.   This
is how the server app knows when it's safe to shutdown.

ComServ.ComServer also has an OnLastReleased event that's called when
the count is decremented to zero.

Re:Constructors and Destructors in Automation objects


There is a procedure called "Initialize" which you can override. It is
called
right after the object is constructed. Also you can override the standard
"destroy" destructor.

Re:Constructors and Destructors in Automation objects


Quote
> When I try to create a constructor that overrides the default constructor
> inherited from TAutoObject, I get an error saying that you can't override
a
> static method. I tried creating the constructor anyway without override.
> Delphi lets me do this, but it doesn't seem to generate any code for the
> constructor. The code I put in the constructor is never executed.

You just override the initialize method instead of a constructor.  You can
do your setup stuff there and shutdown in the destructor.  The other
response is an easier way to get the reference count, it's already done for
you.

Peter Steele

Other Threads