Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I force database updates?

Posted on 2000-05-03
5
Medium Priority
?
149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Expert Comment

by:shenqw
ID: 2776254
//try

 Table1.Refresh
0
 
LVL 7

Accepted Solution

by:
Motaz earned 800 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 Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

715 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