Subject Re: [IBO] AV Problem
Author Helen Borrie
At 11:47 PM 7/12/2003 -0500, you wrote:


>D6/IBO/Intraweb
>
>I'm using IBO with an Intraweb application and I am having problems with
>a consistent AV. The AV happens at the line:
>
>"TIB_Component( ACmp ).CheckSession( AllowDefault );" in the code
>snippet below of the IB_Components.pas:
>
>
>procedure GrabSession( const ACmp: TComponent );
> begin
> if ACmp is TIB_Session then
> ASession := TIB_Session( ACmp )
> else
> if ( ACmp <> Self ) and
> ( ACmp is TIB_Component ) then
> begin
> TIB_Component( ACmp ).CheckSession( AllowDefault ); // <==== AV
> ASession := TIB_Component( ACmp ).FIB_Session;
> end;
> end;
>
>The IBODatabase is created when the UserSession is created which as like
>a datamodule specific to the session (thread), but I see that the above
>proc is called 9 times before the session is even created, when the
>application starts up. During the session, I create IBODatasets and
>IB_Transactions in code, use them, commit the trans and free both. I
>can do this as many times as I like until the session is closed and the
>following code is called:
>
>If IBDB.Connected Then
> IBDB.Disconnect;
>
>...in the Destroy event of the Session.
>
>However, the very next time that the "GrabSession" proc is called, I get
>an AV at the line indicated above. I must not understand correctly how
>IBO works because I can't see the reason for this. Each UserSession
>contains its own IBODatabase and each UserSession is created in the
>context of a thread. The connection is closed when the session ends.
>However, the code above looks like its looking for some kind of session
>object that is global within the application?
>
>Should I be using separate IBODatabases for each session? I assumed it
>was like IBX where to be threadsafe, you need to create a separate
>IBDatabase component for each thread (or using some kind of pooling
>mechanism).
>
>Any help would be appreciated. :)

It's a pretty simple solution, I think. What it looks like, is you are
leaving it to IBO to create a default session. It will do that as soon as
a TIB_Component's Create method is called, and it won't let that go as long
as there a ib_components anywhere in the application - so, in that sense,
it is "global".

What you need to do is instantiate the IB_Session yourself, *before* any
other ib_component's Create method gets called. Make *certain* that it is
the very first ib_component in the creation order; otherwise the code you
quoted will run and create a default session. When you're creating and
destroying your datamodules in threads this is definitely not what you want.

Helen