[SOLVED] Adding a record and updating in one form lazarus / 16-Databases ---------------------------------------------------------------------- Pe3s · 2022-11-11 09:33 Hello, I have a question if it is possible to add a record and update it using the same form. In order not to create a separate window for adding and a separate window for updating existing records? Regards ---------------------------------------------------------------------- Zvoni · 2022-11-11 09:38 That's just plain code-logic. I have something like this. I use a StringGrid to display existent Records. If i select a record from the Grid, my code goes into "Update"-Mode. Any Changes are considered an Update. Additionally i have a Button "New". Once clicked, code goes into INSERT-Mode (cleaning up any Controls which might have been filled beforehand). I'm pretty sure, other people will advise to use Databound controls (DBGrid et al), where it's easy too, to add, delete or update records. many ways to skin that cat. No need for separate Forms ---------------------------------------------------------------------- Pe3s · 2022-11-11 10:15 @Zvoni as for the logic of the code, a conditional statement is enough? ---------------------------------------------------------------------- Zvoni · 2022-11-11 11:20 Quote from: Pe3s on November 11, 2022, 11:15:53 am@Zvoni as for the logic of the code, a conditional statement is enough? Pretty much. Don't get me wrong: Using DB-bound Controls is a viable way, it's just that in basically 25 years i've never used them, since i like to have control over what is happening. So if you want to do it yourself: I have a Variable which is valid for the scope of the Form (could be "global", could be a property of the Form, of a Class i use there, whatever). This variable is "out of the gates" always first in Update-Mode (or if i use an Enum the third state: Undefined). Click on the Grid (selecting a record) definitely switches the Update- Mode on. Change what you have to change (i use separate TEdit's for that). Click on Save, DB gets UPDATED. Click on "New"-Button: Switch to INSERT-Mode, clear the TEDit's, enter new Data, hit Save, record gets INSERTED into DB. In both cases, when hitting "Save" i check the State of the Variable (Undefinded, Update, Insert). Basically a 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 Case StateVariable OfCase Update: CallUpdateSQLStatement;Case Insert: CallInsertSQLStatement;Case Undefined: ShowMessage('Ooops');End; Done ---------------------------------------------------------------------- Pe3s · 2022-11-11 15:11 @Zvoni, Thank you