Lazarus

Programming => Databases => Topic started by: daveinhull on December 01, 2018, 09:56:25 am

Title: Query with edit state
Post by: daveinhull on December 01, 2018, 09:56:25 am
Hi,

Can anyone help or point me to some documentation.

I have a DBGrid which is the only control.

There is an Enter routine:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.DBGrid1Enter(Sender: TObject);
  2. begin
  3.   sqlQuery1.first;
  4.   sqlQuery1.edit ;
  5.   showstate(sqlquery1);
  6. end;

Where showstate just goes to a function that converts the SQL state into a string and at this point it shows the state is EDIT.

I then have an ColExit routine

Code: Pascal  [Select][+][-]
  1. procedure TForm1.DBGrid1ColExit(Sender: TObject);
  2. begin
  3.   if DBGrid1.SelectedField.FieldName = 'FuelDate' then
  4.   begin
  5.     ShowState(sqlquery1);
  6.     DBGrid1.SelectedField.Value := '12/12/2018';
  7.   end
  8. end;

The only thing I do once loaded is press Tab and the State is now shown as BROWSE in the ColExit routine. The Tab key should move it to the next cell.

I can't figure out where or why it is going between Edit and Browse when only the Tab key is pressed.

Any help would be most appreciated.

Dave
Title: Re: Query with edit state
Post by: mangakissa on December 03, 2018, 09:06:33 am
use TSQLQuery.state or TDatasource.state or TDBGrid.datasource.state
Title: Re: Query with edit state
Post by: daveinhull on December 04, 2018, 12:45:42 am
Hi mangakissa, yes I use TSQLQuery.state in the show state routine that's how I know it changes state, but I can't figure out why its changing state?
Title: Re: Query with edit state
Post by: kapibara on December 04, 2018, 04:25:33 am
I think when tab is pressed the dbgrid calls Post. The query is returned to Browse state after a Post.

Some talk about that here:
http://www.festra.com/wwwboard/messages/2236.html
Title: Re: Query with edit state
Post by: mangakissa on December 04, 2018, 08:27:04 am
There should be a real problem if the DBGrid.datasource.dataset is doing a post after each exit of the column. If the user is on the last column en uses tab, the record will be post autmatically because the cursor moves to another record.

What would you do excactly when your exit the column.
Title: Re: Query with edit state
Post by: daveinhull on December 04, 2018, 11:17:46 am
Thanks Kapibara for the link, looks a similar problem, but no final solution or reason given.
Hi mangskissa, all I do is press tab with no other code events going on. I'll double check all options, but I think everything was just left as default.
TinyPortal © 2005-2018