[SOLVED] Checking the state of a Query? lazarus / 16-Databases ---------------------------------------------------------------------- What I can do · 2024-10-15 13:21 OS:Windows 10 @64 Lazarus 3.4 Project: Checking to see if a SQLQuery is in the dsEdit or dsInserrt tried  SQLQUery.state in [dsEdit, dsInsert] doesn't seam to work. ---------------------------------------------------------------------- rvk · 2024-10-15 14:04 Quote from: What I can do on October 15, 2024, 03:21:27 pmOS:Windows 10 @64 Lazarus 3.4 Project: Checking to see if a SQLQuery is in the dsEdit or dsInserrt tried  SQLQUery.state in [dsEdit, dsInsert] doesn't seam to work. Then you need to provide more context because the SQLQuery.State in [dsEdit, dsInsert] should work. If you want help... : Show us code. Tell us about that code. ---------------------------------------------------------------------- What I can do · 2024-10-15 21:36 Thanks for the response rvk That gives me the confidence that at least this small element of my code is OK, Now all I have to do is trace down the receive data and to the send data and see where the error is. --------------------------------------------------------- OK, Got it It's the focus of a cell in a DBGrid when dsInsert is set with a DBNavigator at this point all is normal, but... I am using none DB combo boxes to process data before posting. at the moment of leaving focus from the DBGrid to the TComboBox then the dsinsert State returns back to dsbrowes Work around is to intercept the process at SQLQuery.beforeinsert and set the focus to the combobox then let the normal process of dsinsert mode continue. ---------------------------------------------------------------------- rvk · 2024-10-15 21:51 Quote from: What I can do on October 15, 2024, 11:36:47 pmWork around is to intercept the process at SQLQuery.beforeinsert and set the focus to the combobox then let the normal process of dsinsert mode continue. Or find out why the dataset is put back into dsBrowse mode when leaving the TDBGrid. It shouldn't. It should stay in dsEdit with an asterisk before the record in the TDBGrid. Do you have a TDBGrid.OnExit where you Cancel the dsEdit? BTW. If you use a TDBNavigator with TEdits for editing it might be better to set the TDBGrid on rowselect instead of cell select and disable TDBGrid editing. ---------------------------------------------------------------------- What I can do · 2024-10-16 01:19 QuoteOr find out why the dataset is put back into dsBrowse mode when leaving the TDBGrid. It shouldn't. It should stay in dsEdit with an asterisk before the record in the TDBGrid. Do you have a TDBGrid.OnExit where you Cancel the dsEdit? OK, I built this Application Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit uDBGrid; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, DBGrids, StdCtrls,   DBCtrls, odbcconn,odbcsqldyn, SQLDB, DB,ComCtrls; type   { TForm1 }   TForm1 = class(TForm)    ODBCConnection1:TODBCConnection;    SQLTransaction1:TSQLTransaction;    SQLQuery1:TSQLQuery;    DataSource1:TDataSource;    ComboBox1: TComboBox;    DBGrid1: TDBGrid;    DBNavigator1: TDBNavigator;    procedure FormActivate(Sender: TObject);    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);    Function ShowMSG(const M:String;But:TMsgDlgButtons=[mbOK]):Boolean;  private   public   end; var  Form1: TForm1; implementationuses utoolkit; {$R *.lfm} { TForm1 }  Function TForm1.ShowMSG(const M:String;But:TMsgDlgButtons=[mbOK]):Boolean;  begin   Result:=False;   if MessageDlg(M, mtInformation , But,1) in [mrYes,mrOK] then    Result:=True;  end; procedure TForm1.FormActivate(Sender: TObject);var  r,p:Integer;  e,f,ps:String;begin   ODBCConnection1:=TODBCConnection.Create(ODBCConnection1);   ODBCConnection1.DatabaseName:='Access64';   f:=ExtractShortPathName('G:\t\Dad\Program Files\Lazarus\projectsessions\test\MainHelp.mdb');  ODBCConnection1.Connected:=false;  ODBCConnection1.KeepConnection:=false;  e:=ExtractFileExt(F);  ODBCConnection1.DatabaseName:='Access64';//ODBC Manager  if ODBCConnection1.Params.Count>0 then   for r:=0 to ODBCConnection1.Params.Count-1 do     begin      P:=pos('DBQ=', ODBCConnection1.Params[r]);      if p>0 then       ODBCConnection1.Params[r]:='DBQ='+F     end  else   ODBCConnection1.Params.Add('DBQ='+F);  Try   ODBCConnection1.Connected:=TRUE;   ODBCConnection1.KeepConnection:=TRUE;  except   on E: Exception do  ShowMSG('An exception was raised: ' + E.Message);   end;  ODBCConnection1.LogEvents:=[];    SQLTransaction1:=TSQLTransaction.Create(SQLTransaction1);   SQLTransaction1.DataBase:=ODBCConnection1;   SQLTransaction1.Action:=caCommit;   ODBCConnection1.Transaction:=SQLTransaction1;    SQLQuery1:=TSQLQuery.Create(SQLQuery1);   SQLQuery1.DataBase:=ODBCConnection1;   SQLQuery1.Transaction:=SQLTransaction1;   SQLQuery1.AutoCalcFields:=TRUE;   SQLQuery1.Options:=[sqoAutoApplyUpd ates,sqoAutoCommit,sqoKeepOpenOnCommit];   SQLQuery1.Upda]"]>Blockedde:=upWhereAll;   SQLQuery1.UsePrimaryKeyAsKey:=false;   SQLQuery1.DataBase:=ODBCConnection1;   SQLQuery1.Transaction:=ODBCConnection1.Transaction;    DataSource1:=TDataSource.Create(DataSource1);   DataSource1.Dataset:= SQLQuery1;   DBGrid1.DataSource:=DataSource1;  DBNavigator1.DataSource:=DataSource1;  PS:= 'SELECT * FROM HLPMain';   try    SQLQuery1.Close;    SQLQuery1.SQL.Text:=ps;    SQLQuery1.Open;   except    on E: Exception do ShowMSG(ps);   end;end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);begin  DataSource1.Free;  SQLQuery1.Free;  SQLTransaction1.Free;  ODBCConnection1.Free;end; end.  This is as simple as it gets and can reproduce the exact situation constantly and precisely. click Navigator DBGrid will insert the new empty row and waiting for input Now click on the ComboBox and boom no more inseret... now focus on the combobox then click Navigator and everything works fine. +------------------------------------- Update: add the Options but still the same Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   DBGrid1.Options:=[dgAlwaysShowSelection,                    dgCancelOnExit,                    dgColLines,                    dgColumnMove,                    dgColumnResize,                    dgConfirmDelete,                    //dgEditing,                    dgIndicator,                    dgRowLines,                    dgTabs,                    dgTitles                    ]; ---------------------------------------------------------------------- rvk · 2024-10-16 07:17 Quote from: What I can do on October 16, 2024, 03:19:43 amUpdate: add the Options but still the same Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   DBGrid1.Options:=[dgAlwaysShowSelection,                    dgCancelOnExit,                    dgColLines,                    dgColumnMove,                    dgColumnResize,                    dgConfirmDelete,                    //dgEditing,                    dgIndicator,                    dgRowLines,                    dgTabs,                    dgTitles                    ]; Can you try removing that dgCancelOnExit (or remove the checkmark in Options of the TDBGrid). The dgCancelOnExit calls the TDataset.Cancel when you exit the TDBGrid. So when leaving the TDBGrid without posting, the edit gets cancelled and the TDataset returns to dsBrowse. QuotedgCancelOnExit  Indicates an active editing operation is cancelled when the control loses focus. Although it's weird... I got the dgCancelOnExit checked but when I'm edititing the TDBGrid and go to another control, the dataset stays in dsEdit. You can see that by the little edit cursor in front of the row, otherwise it's a triangle. And the TDBNavigator also stays in edit mode. Edit: Forget the dgCancelOnExit. It's only for canceling when there is an dsInsert (not dsEdit) and there has no edits taken place (i.e. empty insert). Only then will the TDBGrid cancel the dsInsert. (not very clear) But... for me the TDBGrid stays in edit mode when it looses focus. So I'm not sure why this is not the case for you. Edit #2: I made a little test-project with memdataset (so no actual database but that's not needed to test dbgrid). Can you check if you have the same here. Keep close attention to the "|" cursor in front of the row that's being edited (and that the DBNavigator stays in edit) when you focus the DBCombobox.