Lazarus

Programming => LCL => Topic started by: Pe3s on November 30, 2022, 09:39:32 pm

Title: SOLVED[] Adding and editing the same form
Post by: Pe3s on November 30, 2022, 09:39:32 pm
I wrote a code whose task is to add and edit on the same form. I wonder if it could be written better, maybe there is another solution?

Form add & edit
Code: Pascal  [Select][+][-]
  1. public
  2.   EditMode: Boolean;
  3.  
  4. OK button
  5.  
  6. with AddForm do
  7. begin
  8.   if EditMode = True then
  9. begin
  10. // edit
  11. end else
  12. begin
  13. //Add
  14. end;
  15. end;
  16.  

Main form button Add

Code: Pascal  [Select][+][-]
  1. Form2.EditMode:= False;
  2. Form2.ShowModal;
  3.  

Main form button Edit

Code: Pascal  [Select][+][-]
  1. Form2.EditMode:= True;
  2. Form2.ShowModal;
  3.  
Title: Re: Adding and editing the same form
Post by: ASerge on November 30, 2022, 09:49:46 pm
I wrote a code whose task is to add and edit on the same form. I wonder if it could be written better, maybe there is another solution?
You can make the form passive. In this case, the calling code uses either an existing record or creates a new one. Then it calls the edit form for this entry. And if the cancellation has passed, it deletes the new entry.
Title: Re: Adding and editing the same form
Post by: Pe3s on December 01, 2022, 07:48:15 am
Thank you
TinyPortal © 2005-2018