Board index » delphi » Emergency - Thread or Cache problem with Paradox

Emergency - Thread or Cache problem with Paradox

Hi everyone,

    Thank you for taking the time to read this post. I have a mutli-thread
application (Main thread and Working thread) both threads are using the same
database to Edit, Add or Delete records. Each thread is on a seperate
Session like suggested in Borland Documentation. My problem is that when I
close the application (most of the time) I lost records in the database.
Even records that have not been changed during the last session.

    It's not my first application in Delphi and it never happend to me
before. But it's the first time i'm using a thread to access a database.
There's maybe some rules I don't know and things that would be very
important to do in this particular case.

ANY help will be appreciated!

Sylvain Fortin
Computer Programmer

*** Please Reply to Newsgroups ***

 

Re:Emergency - Thread or Cache problem with Paradox


By using 2 sessions you are in fact using 2 applications that access the
database simultaniously.
For multi-user databases you should set Configuration | Drivers | System |
INIT | LOCAL SHARE to TRUE in the BDE Administrator.

"Sylvain Fortin" <NoS...@sympatico.ca> schreef in bericht
news:Y2H57.947$jo4.190617@news20.bellglobal.com...

Quote
> Hi everyone,

>     Thank you for taking the time to read this post. I have a mutli-thread
> application (Main thread and Working thread) both threads are using the
same
> database to Edit, Add or Delete records. Each thread is on a seperate
> Session like suggested in Borland Documentation. My problem is that when I
> close the application (most of the time) I lost records in the database.
> Even records that have not been changed during the last session.

>     It's not my first application in Delphi and it never happend to me
> before. But it's the first time i'm using a thread to access a database.
> There's maybe some rules I don't know and things that would be very
> important to do in this particular case.

> ANY help will be appreciated!

> Sylvain Fortin
> Computer Programmer

> *** Please Reply to Newsgroups ***

Re:Emergency - Thread or Cache problem with Paradox


Hi M.H. Avegaart,

    I tried this configuration setting and it didn't change anything. I'm
still loosing records and I can't find any place in the application where
records can be deleted by the application itself. It is very strange cause
i'm not loosing only new records, I'm also loosing old records that haven't
been change during the application session.

If you have any other idea I'll be happy to try it, thank you very much for
your time.

Sylvain Fortin
Computer Programmer

*** Please Reply to Newsgroups ***

Quote
"M.H. Avegaart" <avega...@NOSPAMmccomm.nl> wrote in message

news:9j94d7$b6$1@scavenger.euro.net...
Quote
> By using 2 sessions you are in fact using 2 applications that access the
> database simultaniously.
> For multi-user databases you should set Configuration | Drivers | System |
> INIT | LOCAL SHARE to TRUE in the BDE Administrator.

Re:Emergency - Thread or Cache problem with Paradox


Hi Everyone,

    Should I try to use only one session? What difference with it make, any
idea?

Thank You!

 Sylvain Fortin
 Computer Programmer

 *** Please Reply to Newsgroups ***

Re:Emergency - Thread or Cache problem with Paradox


On Fri, 20 Jul 2001 09:07:18 -0400, "Sylvain Fortin"

Quote
<NoS...@sympatico.ca> wrote:
>If you have any other idea I'll be happy to try it, thank you very much for
>your time.

Maybe you should lock the base when any of the two threads are
updating or inserting records.

Re:Emergency - Thread or Cache problem with Paradox


On Fri, 20 Jul 2001 14:36:07 -0400, "Sylvain Fortin"
Quote
<NoS...@sympatico.ca> wrote:
>    Should I try to use only one session? What difference with it make, any
>idea?

Hi Sylvain,
Try savechanges after every post or delete.
procedure TForm1.Table1AfterPostDelete(DataSet: TDataSet);
begin
  Check(DbiSaveChanges((DataSet as TBDEDataSet).Handle));
end;
Regards
Johan Smit

Re:Emergency - Thread or Cache problem with Paradox


Hi Johan,

    Thank you for taking the time to help me =). I would like to know if
DbiSaveChanges is available in the Standard Version of Delphi. This is the
list of uses included in my Main Form:

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ToolWin, ComCtrls, StdCtrls, DBTables, Db, Buttons, ImgList,
  ExtCtrls, CommInt, inifiles, DBCtrls;

Also, I can't find find DbiSaveChanges in the help file, so I can't find in
wich library it is. Thank you very much and take care.

Sylvain Fortin
Computer Programmer

Quote
"Johan Smit" <smi...@mweb.co.za> wrote in message

news:3b5a60d5.143283@news.mweb.co.za...
Quote
> On Fri, 20 Jul 2001 14:36:07 -0400, "Sylvain Fortin"
> <NoS...@sympatico.ca> wrote:
> >    Should I try to use only one session? What difference with it make,
any
> >idea?
> Hi Sylvain,
> Try savechanges after every post or delete.
> procedure TForm1.Table1AfterPostDelete(DataSet: TDataSet);
> begin
>   Check(DbiSaveChanges((DataSet as TBDEDataSet).Handle));
> end;
> Regards
> Johan Smit

Re:Emergency - Thread or Cache problem with Paradox


DbiSaveChanges is a BDE API call. It is declared the the BDE unit and
documented in the BDE32.hlp help file.

"Sylvain Fortin" <NoS...@sympatico.ca> schreef in bericht
news:rAB67.3589$eY6.105445@news20.bellglobal.com...

Quote
> Hi Johan,

>     Thank you for taking the time to help me =). I would like to know if
> DbiSaveChanges is available in the Standard Version of Delphi. This is the
> list of uses included in my Main Form:

> uses
>   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
>   ToolWin, ComCtrls, StdCtrls, DBTables, Db, Buttons, ImgList,
>   ExtCtrls, CommInt, inifiles, DBCtrls;

> Also, I can't find find DbiSaveChanges in the help file, so I can't find
in
> wich library it is. Thank you very much and take care.

> Sylvain Fortin
> Computer Programmer

> "Johan Smit" <smi...@mweb.co.za> wrote in message
> news:3b5a60d5.143283@news.mweb.co.za...
> > On Fri, 20 Jul 2001 14:36:07 -0400, "Sylvain Fortin"
> > <NoS...@sympatico.ca> wrote:
> > >    Should I try to use only one session? What difference with it make,
> any
> > >idea?
> > Hi Sylvain,
> > Try savechanges after every post or delete.
> > procedure TForm1.Table1AfterPostDelete(DataSet: TDataSet);
> > begin
> >   Check(DbiSaveChanges((DataSet as TBDEDataSet).Handle));
> > end;
> > Regards
> > Johan Smit

Re:Emergency - Thread or Cache problem with Paradox


On Sun, 22 Jul 2001 10:34:07 -0400, "Sylvain Fortin"

Quote
<NoS...@sympatico.ca> wrote:
>    Thank you for taking the time to help me =). I would like to know if
>DbiSaveChanges is available in the Standard Version of Delphi. This is the
>list of uses included in my Main Form:

>uses
>  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
>  ToolWin, ComCtrls, StdCtrls, DBTables, Db, Buttons, ImgList,
>  ExtCtrls, CommInt, inifiles, DBCtrls;

If you have the BDE, it should be there.
Sorry, I should have said:
add DBIProcs
and that this works for TTables, but not TQueries.
You did not state which you use.
Quote
>Also, I can't find find DbiSaveChanges in the help file, so I can't find in
>wich library it is. Thank you very much and take care.

C:\Program Files\Borland\Common Files\BDE\BDE32.hlp on my system
Here is an extract from Undu 9907087.htm:
When testing a database application I had written, I noticed that
occasionally a field would not be updated on closing the form, despite
calling the dataset.post method in the OK button click event. All the
other field updated fine, except one. To make life complicated, the
field that would not update appeared to be selected at random each
time I ran the program.
This problem was not seen when the application was first written, only
when I decided to make the interface a little more flash. After some
more testing it became apparent that the field that did not get
updated was the field that had the focus before I pressed the OK
button. Furthermore, if I updated a field, then moved to a different
field (that wasn't updated), then moved back and then pressed OK, the
field was updated.
After a bit of head scratching, I noticed that the OK button never
received focus (it was not decended from TWinControl). Delving into
the VCL, I found that data-bound controls update their underlying
field during the LostFocus event. If I posted the dataset in the click
event of a non-focused button, the control would never get the chance
to update itself when it lost focus (when the form closed).
The easiest solution was to replace the OK button with a control that
could receive focus. Unfortunately, most good looking 3rd party
buttons are like the delphi speed buttons and are not derived from
TWinControl.
I found rather a nice one on Torry (GradBtn by Harman) and have since
sent him an improved version. This control can receive focus, but
suprisingly is derived from TCustomControl.
If you need to continue using a non-focusing button, you need to write
some code in the click event that temporarily shifts focus away from
the active control. I suppose you could sent a LostFocus message to
the control but windows may not like that (where has the focus gone?).
If anyone knows a way to force a control to update its underlying
field, I would love to know.
The second tricky bug I have seen also relates to non-updating of
controls:
Using TDataset.DisableControls and EnableControls is a great way to
reduce unnecessary work by controls as you play with the underlying
dataset. If you have ever stepped through a program, line by line,
when the form loads and the controls react to data, it is amazing how
much activity is involved.
While the guides suggest you use these methods if you are scrolling
through a dataset (something you should try to avoid anyway), I would
recommend it if all you are doing is a seek / append. You can then
enable the controls and put the dataset into edit mode and you are
away. However, if you use TDataset.DisableControls before
TDataset.Post, the record may not get updated properly. If you disable
after the post, all is well.
Regards
Johan Smit

Re:Emergency - Thread or Cache problem with Paradox


On Mon, 23 Jul 2001 09:14:52 GMT, smi...@mweb.co.za (Johan Smit)
wrote:
<snip>

I think you have just given the answer to a similar problem I had a
few months back. I was using If UpdatesPending on a cached dataset to
test before ApplyUpdates/CommitUpdates. I found if I just changed the
data in one DBEdit control, then clicked the save button, the change
was not posted because the UpdatesPending property was false. Adding a
Post to the dataset before testing for UpdatesPending solved the
problem.

This technique might help for the problem in this thread.

Dan
--
Dan Brennand
CMDC systems, inc.
Configuration Management and Document Control:
visit us at www.cmdcsystems.com
[SPAM block: change at to @ in my e-mail address]

Re:Emergency - Thread or Cache problem with Paradox


Hi Johan,

    Thank you for taking time to answer my question again. I read your post
and i'll add the DBIProcs in my form uses. I hope it will solve my problem.
Only one thing, I read your explanation on your problem and I noticed that
you didn't have the same problem as I do. To answer 1 question, I'm using
TTable and it's the one giving me the problems and NO I'm not using any
DBControls. All my controls are regular Windows controls and I retrieve the
information they contain before each post and I make the changes using
MyTable.FieldByName("MyField").AsType := XXXXX. My problem is that I loose
records and not field updates. The application doesn't delete records by
itself you absolutely need human action to delete something and this
fonction is now hidden and known by me and 1 other person. But again, I'm
still loosing records. I even loose records that were not accessed during
the session.

    I'll try DbiSaveChanges like you told me to do, maybe it will fix my
problem. I really hope so cause I'm going nuts with this problem.

Thank you very much!

Sylvain Fortin
Computer Programmer

Other Threads