Solved

How do I force database updates?

Posted on 2000-05-03
5
141 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 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