PenelopeSkye 1 Posted September 28, 2022 I want to capture the before and after values for specific dbedit boxes in an app I am working on (The point is to capture the user who makes the change and track the changes they are making). I have written 2 procedures, one that inserts the text value before the field is updated and one that inserts the text value after the field is updated I am using OnMouseEnter and OnExit events respectively to do so. The AddUserbefore insert works fine (It is the same code except it captures OldValue instead of NewValue). The AddUserAfter insert works fine as long as the user places the cursor in another field before shutting down the app But if they update the value in the edit box and then shut down the app without placing the cursor in another field first then either the NewValue doesn't show up in the db, or the updated value shows up in the OldValue field. I tried adding the post first but it didn't change anything. What am I doing wrong? Thank you! ############################################################ procedure TfDesignMaster.AddUserAfter(Sender: TObject); var CommandText,userstring,NewValue,qstring: string; TimeOfChange : TDateTime; begin if (dm.tb_design_master.state=dsEdit) or (dm.tb_design_master.state=dsInsert) then dm.tb_design_master.post else ShowMessage('Not open'); with dm do begin userstring := CurrentUserName; NewValue := dbedit13.text; TimeOfChange := VarToDateTime(Now); qString := 'INSERT INTO AdimsUserField (JM_User,NewValue,TimeOfChange) VALUES (:a, :b,:c)'; commandAddUser.CommandText := qstring; commandAddUser.Parameters.FindParam('a').Value := userstring; commandAddUser.Parameters.FindParam('b').Value := NewValue; commandAddUser.Parameters.FindParam('c').Value := TimeOfChange; commandAddUser.Execute(); //ShowMessage(userstring); end; end; Share this post Link to post
Stano 143 Posted September 28, 2022 My experience is that DBEdit only updates the DBTable when entering or exiting the field. Just like you described it here. I too would like to know what event to call to update a value in a DBTable. Now I have a function that reads the text and after conversion saves it to a DBTable. Share this post Link to post
Javier Tarí 23 Posted October 6, 2022 All of the following applies to VCL,; I have zero experience with FMX: You should use OnEnter, not OnMouseEnter If you want it work 100% also when the form is closed, I do this: Save the form Active control value on a variable Assign to ActiveControl another safe control (I do it eg. btnCancel.SetFocus) Assign again to ActiveControl the control you saved This way you are simulating the user leaving the edit box Another way to observe a DB field changes is the TDataSource events: when your field is changed while the dataset is in dsEdit or dsInsert state, you will get a DataChange event refering to that field (and not to nil) Share this post Link to post
PenelopeSkye 1 Posted November 1, 2022 I'm so sorry, I could have sworn I replied to this! I used On Enter and that did the trick, of course it seems obvious in retrospect! Thank you! Share this post Link to post