Recent

Author Topic: SOLVED[] Adding and editing the same form  (Read 256 times)

Pe3s

  • Sr. Member
  • ****
  • Posts: 330
SOLVED[] Adding and editing the same form
« 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.  
« Last Edit: December 01, 2022, 07:48:47 am by Pe3s »

ASerge

  • Hero Member
  • *****
  • Posts: 2049
Re: Adding and editing the same form
« Reply #1 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.

Pe3s

  • Sr. Member
  • ****
  • Posts: 330
Re: Adding and editing the same form
« Reply #2 on: December 01, 2022, 07:48:15 am »
Thank you

 

TinyPortal © 2005-2018