Recent

Author Topic: [SOLVED] Closing a form error: DataSet is not in edit or insert state ...  (Read 617 times)

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 370
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
I've run into this once in awhile but deciding that I am not checking properly when a form in this database app is closed. If I open and edit or insert not an issue but if in testing I open a form and just move to the next record and then click the Close button, I'm checking whether the user might have edited a record to make sure to post before closing for example:
Code: Pascal  [Select][+][-]
  1. procedure TFrmSalesOrdersMgt.SpdBtnCloseSOClick(Sender: TObject);
  2. begin
  3.   try
  4.     if DbfSO.Modified then
  5.       DbfSO.Post;
  6.   finally
  7.     DbfSO.Close;
  8.   end;
  9.   DbfProposal.Close;
  10.   DbfContacts.Close;
  11.   DbfPhotogrphr.Close;
  12.   DbfFirmType.Close;
  13.   DbfJobType.Close;
  14.   DbfStatus.Close;
  15.   FrmSalesOrdersMgt.Close;
  16.   FrmSalesOrdersMgt.Free;
  17. end;

Is there a better way to check other than if DbfSO.Modified ? See attached error.
Tks anyone
« Last Edit: October 25, 2024, 08:29:59 pm by 1HuntnMan »

Handoko

  • Hero Member
  • *****
  • Posts: 5436
  • My goal: build my own game engine using Lazarus
Re: Closing a form error: DataSet is not in edit or insert state ...
« Reply #1 on: October 23, 2024, 07:01:17 pm »
I am not sure but maybe:

Code: Pascal  [Select][+][-]
  1.   if DbfSO.Active then
  2.     if(DbfSO = dsEdit) or (DbfSO = dsInsert) then
  3.       try
  4.         DbfSO.Post;
  5.       finally
  6.         DbfSO.Close;
  7.       end;

If you get a compile time error, you need to put DB in the uses clause.
« Last Edit: October 23, 2024, 07:06:29 pm by Handoko »

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 370
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Closing a form error: DataSet is not in edit or insert state ...
« Reply #2 on: October 24, 2024, 06:04:40 pm »
Tks Handoko, made it work ...

Code: Pascal  [Select][+][-]
  1.   if DbfSO.Active then
  2.     if (DSSO.DataSet.State = dsEdit) or (DSSO.DataSet.State = dsInsert) then
  3.       try
  4.         DbfSO.Post;
  5.       finally
  6.         DbfSO.Close;
  7.       end;
  8.  

 

TinyPortal © 2005-2018