Solved

How do I force database updates?

Posted on 2000-05-03
5
147 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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