Solved

How do I force database updates?

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month3 days, 13 hours left to enroll

630 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