Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Databases are just plain weird.. 1

Status
Not open for further replies.

RobPouwelse

Technical User
Nov 19, 2001
77
NL
I've got a strange one!! :)
I'm using a DBGrid, Datasource and a Table.
Datasource.Dataset = Table;
DBGrid.Datasource = Datasource;

So, DBGrid shows Table..
I've made Table active so i can change the contents of the database. Now the weird part comes in :)
When i change a record and i exit the cell by pressing ENTER the DBGrid is updated but when i close the program and run it again, IT THE SAME AS IT WAS BEFORE!! arg!! :)
now when i change a record and exit by clicking another cell, the DBGrid is updated and the database is too!! , this is just too weird.
E-mail: Rob@matas.nl (till Jan 10, from then on it's Deathwish@winning.com)
 
Its all about open, edit, and close the database has to be edit mode for data to be entered or edited, ensure to close the database on exiting your application, put a proper close button with the command to close the dbase on exit

good luck
 
I am using:

Procedure Shutdown;
begin
Table1.Close;
Application.Terminate;
end;

so, the database is closed when the application is terminated. So that's not what causes it. (btw: i don't use CachedUpdates. E-mail: Rob@matas.nl (till Jan 10, from then on it's Deathwish@winning.com)
 
The default jumping from record to record is the Tab key.

The next code intercepts the Enter key:

Procedure TForm1.FormCreate(Sender: TObject);

begin
Application.OnMessage := Substitute_Enter_by_Tab;
end;

procedure TForm1.Substitute_Enter_by_Tab(var Msg: TMsg; var Handled: Boolean);
begin
if Msg.message = WM_KEYDOWN then
begin
if Msg.wParam = VK_RETURN then
Keybd_event(VK_TAB,0,0,0);
end;
end;
S. van Els
SAvanEls@cq-link.sr
 
It might be that your dbgrid isn't losing focus so the record isn't writing to the database. You might set focus to something else in your shutdown, as a workaround. Calling Table1.UpdateRecord might also fix the problem.

TealWren
 
You say that it saves when you click on another cell. Are you clicking a cell on another row?. Changing rows in a dbGrid does an implicit post of the edited record. Closing a table doesn't.
 
svanels: I tried your method and it didn't work, but that maybe caused by the way the grid works: if the focus in on the same row, the records of that row aren't updated.

TealWren: Focus to what?? i only have the DBGrid :) and about Table1.UpdateRecord:
Project raised an exception in class EDatabaseError with message:"Table1 Dataset not in edit or insert mode" Process Stopped.
i first closed the database, when i don't close it: it wouldn't updated it.(I read the helpfile and it stated that Update record was used for Cached Updates, and i'm not using Cached Updates)

CharlesWright: You're right, when i click on another cells of the same row, it still doesn't update the record. So how do i change rows without having to have the user do it?

E-mail: Rob@matas.nl (till Jan 10, from then on it's Deathwish@winning.com)
 
I think the answer is to put the following code in OnColExit (for the grid) to save changes when moving along a row (i.e. changing column). To save changes if closing the form/application without moving from the cell, put the code in OnClose for the form.

if Table1.State = dsEdit then Table1.Post;

The test avoids the error message you have seen regarding Dataset not in Edit Mode. The process seems odd because the grid invokes edit mode as soon as you start changing a cell (because it saves you the trouble of coding for it). I suppose it does not automatically post until you leave the row because rows tend to correspond to table records and it thererfore saves multiple file updates when several columns are changed.
 
Dooda: tnx, that was excectly what i needed!

tnx to all the others as well, your reply's are greatly appreciated :) E-mail: Rob@matas.nl (till Jan 10, from then on it's Deathwish@winning.com)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top