Dennis,

It was a bad choice of words.  I lumped formcreate code into 
initialisation.  Any non-trivial code to deal with maths, strings, 
objects, forms etc can cause exceptions.  

One of the things that happens in our apps is that they use a
commandline parameter to determine where the data files are - so
that one exe can work with multiple data sets.  This is set in the
datamodule for the project which contains the TDatabase component
for the project.  Before I put the try except in, an invalid path 
would cause each form to generate multiple exceptions.  So I 
have trapped it, and that works.

The problem remaining is that the VCL still gives me two (sometimes
3) more exceptions after that.  I dont really want to use a
messagebox to display the exception message and use halt.  But I
might have to.

Your point about the initialisation code is taken.  I hadnt yet 
thought about it, but it is a worry as well.  There should be 
automatic try-except block around the main dpr code.

On  7 May 99 at 11:08, Dennis Chuah wrote:

> 
> Rohit,
> 
> Firstly, unit initialization happens BEFORE your try-except clause.  In
> fact, unit initialization happens BEFORE the begin.  So what can you do
> about this?
> 
> 1.  Put all initialization / finalization code that can raise exceptions
> into procedures in the unit(s).
> 
> 2.  Create a new unit.
> 
> 3.  Use the SysUtils unit and the other units with initialization /
> finalization code moved into procedures.
> 
> 4.  In the initialization section, call all the initialization code.  This
> way, if one of them raises an exception, the others will automatically be
> skipped.  With this you can also explicitly control the order in which the
> units are initialized.
> 
> 5.  Do the same for finalization, except that you reverse the order in which
> you call finalization code.
> 
> Hope this helps.
> 

Rohit

======================================================================
CFL - Computer Fanatics Ltd.  21 Barry's Point Road, AKL, New Zealand
PH    (649) 489-2280 
FX    (649) 489-2290
email [EMAIL PROTECTED]  or  [EMAIL PROTECTED]
======================================================================

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to