Recent

Author Topic: Query with edit state  (Read 2868 times)

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Query with edit state
« 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
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Query with edit state
« Reply #1 on: December 03, 2018, 09:06:33 am »
use TSQLQuery.state or TDatasource.state or TDBGrid.datasource.state
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: Query with edit state
« Reply #2 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?
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

kapibara

  • Hero Member
  • *****
  • Posts: 610
Re: Query with edit state
« Reply #3 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
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Query with edit state
« Reply #4 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.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: Query with edit state
« Reply #5 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.
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

 

TinyPortal © 2005-2018