Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi initialization problems

Status
Not open for further replies.

c567591

MIS
Aug 12, 2002
67
US
I have an application that was written by someone else. Sigh.

Anyway I am getting an access violation when it cannot connect to the database (MSSQL).
After hours of single stepping, I traced it to the destructors of the classes that are failing because the classes didn't get initialized right in the 1st place.

I am just trying to check our configuration and validate things before all these classes get created.

I tried inserting something between the main begin
and the Application.Initialize; lines as this seemed logical to me, but it never ran.
With a breakpoint on begin, then stepping into then next line gets me hip deep in our constructors where it is choking on the db not being found.
This is *before* the forms are created.
I tried in the main form create, but this was too late as well.

Why can I not step though the constructors?
How do I put off the constructors until after
I have validated things?

This is driving me nuts, I rather thought I understood Delphi program initialization.

Thanks,
Matt
 
are you using ado components for connection to mssql?
if so is the 'active' property of the TADOConnection component set to true?

--------------------------------------
What You See Is What You Get
 
Yes, it is using ADO.
Yes some are set to active.

Why would this matter if thier form is not yet created?
 
It is easier to active them at runtime and catch any exception if the db connection is not available.

regarding the 'order' of initialization in delphi : don't forget that, if you have units that have an 'initialization' part (at the end of the unit) these will be executed FIRST (even if this unit contains object code) maybe that's your problem...

--------------------------------------
What You See Is What You Get
 
Have you tried connecting with SQL Explored or ODBC Manager? Perhaps you are takeing the highlevel approach to a low level problem. Be sure ypu can connect outside of you delphi app. Once established, go back to your program. Put connect to database before opening any forms, particularly if it has any data aware controls. Are you reeping all the benefits of tdatamodule? I put my DataMod:= tdatamod.create() in the create method of my mainform to be sure. Putting a halt in the exception block forces data setup before your program will run. Frees you from having to write all those "what if's
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top