PenelopeSkye 1 Posted September 7, 2022 I am trying to update an app. I type 871 into an edit box and close the app. When that happens I check the database. The cell associated with the DBEdit23 field is 871, but the IsMetallic field is not updated. What am I doing wrong? Please let me know what other info you need. Thanks! procedure TfDesignMaster.DBEditPMSExit(Sender: TObject); begin if DBEdit23.Field.AsString ='871' then begin dm.dsVendorProd.DataSet.Edit; dm.dsVendorProd.DataSet.FieldByName('IsMetallic').Value:='Y'; dm.dsVendorProd.DataSet.Post; end; end; Share this post Link to post
PenelopeSkye 1 Posted September 7, 2022 Sorry, I am trying to update a database!!! Share this post Link to post
Brian Evans 105 Posted September 7, 2022 (edited) Exit is not triggered for a control when the application is closed as focus never moves off it. You could move focus somewhere in the form's OnClose to trigger it. procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin Form1.SetFocusedControl(Form1.Button1); end; Edited September 7, 2022 by Brian Evans Share this post Link to post
PenelopeSkye 1 Posted September 7, 2022 Hi Brian! After seeing your post (thank you!) just to test the basic code I updated the text in the edit box, manually moved focus to another tab, then exited. Shouldn't that have updated the database? Sorry if I am being obtuse! Share this post Link to post
Brian Evans 105 Posted September 7, 2022 If that is hooked up to the edit in question. I have doubts since DBEditPMSExit wouldn't be the default event name for a control called DBEdit23. Share this post Link to post
PenelopeSkye 1 Posted September 7, 2022 (edited) Erm... I created that name. I modeled it on another procedure called procedure DBEdit19Exit(Sender: TObject). I just assumed they made that up as well. Thanks Brian! Edited September 7, 2022 by PenelopeSkye Share this post Link to post
PenelopeSkye 1 Posted September 7, 2022 (edited) I changed my code to procedure TfDesignMaster.DBEdit23Exit(Sender: TObject) but it didn't work. FYI that I have also tried FieldByName('IsMetallic').AsString This is the code for a similarly named procedure. Does my procedure not work because I am trying to write to a db and they are not? Apologies for my noobness. procedure TfDesignMaster.DBEdit19Exit(Sender: TObject); var stuffCustom: string; begin if (dm.tb_design_master.state=dsEdit) or (dm.tb_design_master.state=dsInsert) then begin //MessageDlg( 'From DBEdit19 designmaster IS in dsEdit or dsInsert', mtInformation, [mbOK], 0); if Length(DBEdit19.Field.AsString) > 0 then begin stuffCustom:='Custom'; wwDBLookupCombo2.Value:=stuffCustom; end; end else //MessageDlg('From DBEdit19 designmaster IS NOT in dsEdit or dsInsert', mtInformation, [mbOK], 0); end; Edited September 8, 2022 by PenelopeSkye Share this post Link to post
Lajos Juhász 293 Posted September 7, 2022 This logic most probably belongs to the field's onchange. Share this post Link to post
Stano 143 Posted September 8, 2022 OT if (dm.tb_design_master.state=dsEdit) or (dm.tb_design_master.state=dsInsert) then I prefer to use if (dm.tb_design_master.state in [dsEdit, dsInsert) then In such cases if Length(DBEdit19.Field.AsString) > 0 then I use if Length(Trim(DBEdit19.Field.AsString)) > 0 then Share this post Link to post
PenelopeSkye 1 Posted September 8, 2022 I will work with these, thank you!!! Share this post Link to post
PenelopeSkye 1 Posted September 9, 2022 (edited) To everybody who answered this thread: Apologies! I had no idea that you had to highlight the object, go to events, and add the procedure name!! Edited September 9, 2022 by PenelopeSkye Share this post Link to post