Board index » delphi » Possible bug in IBX 4.6 freeing TIBDatabase

Possible bug in IBX 4.6 freeing TIBDatabase

Jeff:

I'm seeing an error in my app after installing 4.6 where if the application
is closed before the database is connected (say, by hitting cancel on the
login screen), an exception is raised in the TIBDatabase.Free component when
the unit that contains the componenent is released. The error only occurs if
the unit is freed before I call Application.Run in the project file:

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};
  // Form1 only contains a TIBDatabase component

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  //Application.Run;
  // With this line above commented out, the exception will be raised.
end.

For now, I'm working around it by creating the IBDatabase component at
run-time.

Thanks,

Dan

 

Re:Possible bug in IBX 4.6 freeing TIBDatabase


The problem lies in the fact that there is a call to EnterCriticalSection, but
in the case you have described the Application is in the process of unwinding
itself.  So the RTL is erroring because of the timing (the finalization section
gets called before the Form is actually destroyed so the Critical section is
released that is needed).  What I suggest is to call the Form's Release method
if you are going to shut down because of an invalid login.  This will free the
Form (and consequently the IBDatabase) before the unwinding occurs.

My only other alternative would be to eat the exception in the RemoveWriter
method and I don't like just eating Exceptions like that.

another alternative is to instead of bypassing the Application.Run do this

  Application.ShowMainForm := false;
  Application.Terminate;

and then let Application.Run go normally.  You should not see the main form at
all, and the key piece to this which is the setting of
AddExitProc(DoneApplication); in the Applcation.Run.  The DoneApplication makes
certain that the objects are destroyed before the finalization sections start
firing.  When you by pass this you can cause a lot of problems if you don't
clean up yourself.

How are you freeing the MainForm?  I tried this

  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Form1.Free;
  Application.Run;

which does what you seem to be stating, "The error only occurs if the unit is
freed before I call Application.Run" and I don't get an error with or without
the Application.Run line.

Quote
Dan Palley wrote:

> Jeff:

> I'm seeing an error in my app after installing 4.6 where if the application
> is closed before the database is connected (say, by hitting cancel on the
> login screen), an exception is raised in the TIBDatabase.Free component when
> the unit that contains the componenent is released. The error only occurs if
> the unit is freed before I call Application.Run in the project file:

> program Project1;

> uses
>   Forms,
>   Unit1 in 'Unit1.pas' {Form1};
>   // Form1 only contains a TIBDatabase component

> {$R *.RES}

> begin
>   Application.Initialize;
>   Application.CreateForm(TForm1, Form1);
>   //Application.Run;
>   // With this line above commented out, the exception will be raised.
> end.

> For now, I'm working around it by creating the IBDatabase component at
> run-time.

> Thanks,

> Dan

--
Jeff Overcash (TeamB)   I don't think there are any Russians
(Please do not email    And there ain't no Yanks
 me directly unless     Just corporate criminals
 asked.  Thank You)     Playing with tanks.  (Michael Been)

Other Threads