Solved

How do I force database updates?

Posted on 2000-05-03
5
134 Views
Last Modified: 2010-04-04
I am using Delphi 5 pro. I have a simple demonstration system for a class assignment I am giving my students that uses the DBE.

The problem is that I post records but do not see them until I exit the program and re-run it.

Problem details
I have two Ttable components in a master detail relationship, tblStaff is the master, tblStaffJob is the detail.
On one form I append and post a job record using tblStaffJob. I then go to another form where I calculate the pay due to staff for the jobs they have done.
The code on this form loops through the staff records using tblStaff and for each staff record looks at all the jobs for that staff member using tblStaffJob.
The problem is that this does not find the latest tblStaffjob record unless I halt the program and start it again before running the staff pay program.
.
All table components are on a datamodule so the two forms use the same tblStaff and tblStaffJob Ttable components.

I would be glad of help on this - Dan
0
Comment
Question by:seabear
5 Comments
 
LVL 3

Expert Comment

by:shenqw
ID: 2776254
//try

 Table1.Refresh
0
 
LVL 7

Accepted Solution

by:
Motaz earned 200 total points
ID: 2776259
Table1.FlushBuffers;

Motaz
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 2776635
this is what i've posted some time ago to a similar question:

>>

if u've got sql u have 2 use DbiSaveChanges, since DbiUseIdleTime doesn't work w/ sql:

that one is 2 b used explicitly, i.e. every time u wanna write the changes 2 disk, u've gotta make a call 2 DbiSaveChanges like this:

....
Table1.Edit;
Table1.FieldByName('Name').AsString := 'Mr. X';
Table1.Post;
DbiSaveChanges(Table1.Handle);
....

this way u can control when the changes r updated.

if u've got no sql, u can use DbiUseIdleTime.

just put it in2 the applications onidle:

TForm1.FormCreate(Sender: TObject);
....
Application.OnIdle := MyIdle;
....

TForm1.MyIdle(Sender: TObject; var Done: Boolean);
begin
  // if u set Done 2 False, this procedure will not call win api's waitmessage so this procedure will b called repeatedly, what'd cause excessive cpu-time...
  DbiUseIdleTime;
end;

don't 4get 2 put DbiProcs in the uses-clause.

<<

well, motaz' answer is completely ok, since flushbuffers calls dbisavechanges...

;-)

and if you want to be on the safe side, disable windoze' cached updates.

regards,

BlackDeath.
0
 
LVL 2

Expert Comment

by:isstorr
ID: 2777365
here is my simple TTable2 component which just overrides the Post method of TTable -
now just replace all your TTables with TTable2's -


unit Table2;

interface

uses
  DbiProcs, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBTables;

type
  TTable2 = class(TTable)
  public
    // Public declarations
    procedure Post; override;
  end;

procedure Register;

implementation

procedure TTable2.Post;
begin
   inherited Post;
   DbiSaveChanges(handle);
end;


procedure Register;
begin
  RegisterComponents('Symos', [TTable2]);
end;

end.
0
 

Author Comment

by:seabear
ID: 2779192
Thanks to everyone who sent comments, FlushBuffers seems to work well in this case - Dan
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now