Recent

Author Topic: SqlQuery update status  (Read 269 times)

Hansvb

  • Sr. Member
  • ****
  • Posts: 413
SqlQuery update status
« on: June 20, 2022, 03:30:05 pm »
Hi,

The user can make changes in a table via a DbGrid. Now I only want to save if there are actually mutations. How can you check for that?
I thought of doing this with SqlQuery.UpdateStataus. But this only seems to be activated if you first go to a following line in the DbGrid. I want to see the UpdateStatus change as soon as I exit the cell. Is that possible?

Code: Pascal  [Select][+][-]
  1. procedure TFrm_Main.DBGridMain1ColExit(Sender: TObject);
  2. begin
  3.   case DataModuleMain.SQLQuery1.UpdateStatus of
  4.    usUnmodified :  Button2.Caption:='usUnmodified';
  5.    usModified :  Button2.Caption:='usModified';
  6.    usInserted :  Button2.Caption:='usInserted';
  7.    usDeleted :  Button2.Caption:='usDeleted';
  8.   end;
  9. end;  
« Last Edit: June 20, 2022, 06:01:39 pm by Hansvb »

Zvoni

  • Hero Member
  • *****
  • Posts: 1274
Re: het SqlQuery update status
« Reply #1 on: June 20, 2022, 03:56:09 pm »
Why not use OnSelection-Event?
You need variables for oldValue, oldRow and oldCol where you save Row and Col when selecting a cell
OnSelection ships Col and Row of the newly selected Cell
Compare newValue to oldValue of Cell at "old" Col/Row, if "dirty" then update. Set oldCol/oldRow to current Col/Row, oldValue to current value
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Hansvb

  • Sr. Member
  • ****
  • Posts: 413
Re: SqlQuery update status
« Reply #2 on: June 20, 2022, 07:47:47 pm »
Found something which i can use: Datasource.state. if a cell in DbGrid is changed the datasource state changes.

To see what happens when a cell changes:
Code: Pascal  [Select][+][-]
  1. procedure TDataModuleMain.DataSource1StateChange(Sender: TObject);
  2. begin
  3.   case DataSource1.State of
  4.   dsInactive:
  5.     begin
  6.       ShowMessage('dsInactive');
  7.     end;
  8.   dsBrowse:
  9.     begin
  10.       ShowMessage('dsBrowse');
  11.     end;
  12.   dsEdit:
  13.     begin
  14.       ShowMessage('dsEdit');
  15.     end;
  16.   dsInsert:
  17.     begin
  18.       ShowMessage('dsInsert');
  19.     end;
  20.   dsCalcFields:
  21.     begin
  22.       ShowMessage('dsCalcFields');
  23.     end;
  24.   dsCurValue:
  25.     begin
  26.       ShowMessage('dsCurValue');
  27.     end;
  28.   dsNewValue:
  29.     begin
  30.       ShowMessage('dsNewValue');
  31.     end;
  32.   dsOldValue:
  33.     begin
  34.       ShowMessage('dsOldValue');
  35.     end;
  36.   dsFilter:
  37.     begin
  38.       ShowMessage('dsFilter');
  39.     end;
  40.   end;
  41. end;  


 

TinyPortal © 2005-2018