Board index » delphi » System has been illegally re-entered

System has been illegally re-entered

Hi everyone

Please could someone help tell me what this error message means - I keep on
getting it when I deploy my app. I can't seem to get it on my system. I am
using D2, assync pro, and flashfiler. I have searched all the error codes I
know but I don't seem to be able to find this one. HELP!

Many Thanks

Shaun Smith
Associated Software Consultants

 

Re:System has been illegally re-entered


Shaun,

I getting the same problem with D2 with a Paradox database but not the same
components.

Like you I can not duplicate the error on my development system but it
occurs randomly but always during the same call to a dll I developed.  I
also have a tquery that runs in a thread but shouldn't cause this problem.

Jerry

Quote
Shaun Smith wrote in message <7adv7v$8i...@forums.borland.com>...
>Hi everyone

>Please could someone help tell me what this error message means - I keep on
>getting it when I deploy my app. I can't seem to get it on my system. I am
>using D2, assync pro, and flashfiler. I have searched all the error codes I
>know but I don't seem to be able to find this one. HELP!

>Many Thanks

>Shaun Smith
>Associated Software Consultants

Re:System has been illegally re-entered


Hi

If you access your DB from different threads you have to use sessions
for this. D3 has a TSession component in D2 you have to do it by code.
As far as I know do async pro events (data triggers) fire in the
context of a different thread than the main thread. So you have to be
careful when accessing your DB from within a async pro event handler.
Reentering the BDE from a different thread may corrup BDE internal
datastructures which causes this error.

In D3 there is a bug in the VCL which also causes this error. It might
be present in D2 too although I'm not sure. To work around this bug:

1. *Don't* prepare your query. Instead of

if not MyQuery.prepared then
  MyQuery.prepare;
MyQuery.open;                    

just use MyQuery.open The VCL takes care about preparing anyway so
performance shouldn't be a matter. The reason for this is that if you
explicitly prepare the query the VCL sometimes executes some BDE API
calls in the context of the wrong session on consecutive calls to
MyQuery.open.

2. Explicitly set the correct session right before executing the
query:

if not MyQuery.prepared then
  MyQuery.prepare;
DbiSetCurrSession(MySession.Handle);
MyQuery.open

If you want I can (re)post the internals about his bug. Or just search
on dejanews for my previous posts about this issue.

Michael

Quote
"Shaun Smith" <asc...@dbn.lia.net> wrote:
>Hi everyone
>Please could someone help tell me what this error message means - I keep on
>getting it when I deploy my app. I can't seem to get it on my system. I am
>using D2, assync pro, and flashfiler. I have searched all the error codes I
>know but I don't seem to be able to find this one. HELP!
>Many Thanks
>Shaun Smith
>Associated Software Consultants

Re:System has been illegally re-entered


Mike,

Thanks for the info!

I was using the default Session for the main program and a different session
for the threaded query.

Do I have to create/destroy the form where the threaded tquery is located
each time the thread executes?  Currently, I create the form when the app
starts and destroy it when the app terminates.

Jerry

Re:System has been illegally re-entered


Jerry,

It shouldn't matter when you create/destroy the form. You have to make
sure that each thread accessing your DB does so in the context of a
different session. That means you have to create a session object for
each thread and assign it to all TTable, TQuery... components
accessing the DB from within this thread. If you fail to do so you
will get this 'illegally re-entered' message sooner or later.

However at least in D3 there is a bug which messes things up when
working with TQuery (fixed in D4). I dont know if this applies for D2
but you might want to try this for each query (also the queries in the
main thread!):

if not MyQuery.prepared then
  MyQuery.prepare;
DbiSetCurrSession(MySession.Handle);           // Add this line!
MyQuery.open

Where MySession is the session for the current thread.

Michael

Quote
"Jerry Martinez" <intercalie...@yahoo.com> wrote:
>Mike,
>Thanks for the info!
>I was using the default Session for the main program and a different session
>for the threaded query.
>Do I have to create/destroy the form where the threaded tquery is located
>each time the thread executes?  Currently, I create the form when the app
>starts and destroy it when the app terminates.
>Jerry

Re:System has been illegally re-entered


Michael,

I took your advise and no problems so far...

Could not forcing the session in the thread cause random "index out of date"
errors as well?

Thanks for the help!

Jerry

Re:System has been illegally re-entered


Jerry,

...

Quote
>Could not forcing the session in the thread cause random "index out of date"
>errors as well?

I never heard about that. As far as I know the 'index out of date'
problem doesn't depend on sessions.
Anyway handling 'index out of date' errors is less trouble than
'system has been illegally re-enterd' errors.

Michael

Re:System has been illegally re-entered


Michael,

What is the best way to protect against 'index out of date' errors besides
tossing Paradox?

Jerry

Re:System has been illegally re-entered


I dont know. Unfortunately this error didn't occure too often to me.
So I used to manually rebuild my index.

Michael

Quote
"Jerry Martinez" <intercalie...@yahoo.com> wrote:
>Michael,
>What is the best way to protect against 'index out of date' errors besides
>tossing Paradox?
>Jerry

Other Threads