Juan wrote:
> What do you propose? I was thinking in raising an exception instead.
>
> On Tue, 14 Nov 2000, Rohit Gupta wrote:
> > In D5+, you shouldnt destroy the object inside the constructor.
Actually, I believe in all versions of Delphi, raising an exception inside a
constructor will cause the destructor to be called.
In fact, inside System.pas, if you look at the asm code for _ClassCreate,
you can see it faking up an exception frame on the stack for the purpose of
calling the Destroy method and then _ClassDestroy should an exception be
raised during the create.
It's actually only part of the story since the _ClassCreate library
implementation 'knows' what sort of code the compiler generates when
TSomething.Create is called - very interesting.
In short, to abort your constructor, just raise an exception. However, you
need to ensure your Destroy method can handle cleaning up a partially
constructed object.
This is also the reason why Delphi initialises all memory of newly created
objects to 0 since it makes it easier for Destroy's of partial objects -
everything is already nil.
Quite an elegant design overall - better than C++ in my experience - mind
you I can't remember what the standards committee decided exceptions in
constructors should mean for C++.
TTFN,
Paul.
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"