Subject Re: [IBO] Out of system resources
Author Geoff Worboys
> I suspect the new problem relates to the login exception occuring
> before all units are initialised - or at least before the main
> window is presented.

I was partly correct. The code in the demo app (conceptually) did
this...

begin
Application.Initialize;
Application.CreateForm(TfMain, fMain);
Application.CreateForm(TfDM, fDM);
fmDM.Connection.Connect;
Application.Run;
fmDM.Connection.Disconnect;
end.

Anyone using this sort of code beware! This places various visual
component creation outside the main program loop - and outside the
exception handling that TApplication puts around that loop - including
a special ExitProc to cleanup after exceptions. This means that any
dialogs or exceptions generated in the prefix and suffix code may
behave unpredictably.

In the particular example I was playing with the updatebar was
initialised OK, and then the exception was generated and the updatebar
unit was finalised BEFORE other components were destroyed. The
destruction of the datamodule sent events to the mainform which then
attempted to reference the updatebar unit - which was no longer
initialised. It all gets a bit hairy :-)

My recommendation is that you place initialisation code inside your
mainform somewhere. Indeed I prefer to only create and destroy
datamodules from inside the mainform - to be sure everything is
configured predictably.

For maximum protection I prefer to only start such interesting
processing as login AFTER the mainform is showing - as this avoids
various other problems. To do this I generally attach code to the
OnShow or OnActivate event and use a flag so that the initialisation
only gets done once.


I dont think this has anything to do with the original problem. I am
going to review what changes were made between Ha an Hc to see if I
can discover what may have altered the circumstances for that problem.

--
Geoff Worboys
Telesis Computing