Recent

Author Topic: Error dbf post ( resolu )  (Read 1477 times)

Fabius

  • Jr. Member
  • **
  • Posts: 59
Error dbf post ( resolu )
« on: June 14, 2021, 09:11:52 am »
Good morning all

It compiles, but at runtime, I have an error, the dataset is not in add or edit mode
While I have placed the APPEND command?

or do I make a mistake?

Thank you for your reply




procedure TForm3.Button4Click(Sender: TObject);
begin
  //////////////////ajouter en fin de table

        if DBEdit1.text <>'' then
    begin
    DBEdit1.Color := clGreen;
    lignesDeSaisie.Last;
    Try
    lignesDeSaisie.Append;
    lignesDeSaisie.FieldByName('compte').AsString := Form1.Xcomptes.FieldByName('compte').AsString;

    lignesDeSaisie.FieldByName('label').AsString := Form1.Xcomptes.FieldByName('label').AsString;
    lignesDeSaisie.Post;
    finally

    end;


   DBEdit3.SetFocus;
    end else begin
          DBEdit1.Color := clRed ;
          messagedlg('Compte NON Trouvé Ou Vide .',mtinformation,[mbok],0);
          StatusBar1.SimpleText:= 'Ce compte n existe pas ';
    end;

end;                   
« Last Edit: June 14, 2021, 10:08:31 am by Fabius »

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: Error dbf post
« Reply #1 on: June 14, 2021, 09:45:04 am »
Your code suggests that you enter the text first, then call Dataset.Append, transfer the edit text and finally post. This is possible with normal TEdit controls, but not with TDBEdit. Since the DBEdit reflects the state of the dataset you cannot enter anything before the dataset has not been switched to edit mode. Therefore, you first must call Dataset.Append, type the text and then Post.

See a working example with TDBEdit in the attachment.
« Last Edit: June 14, 2021, 09:49:47 am by wp »

Fabius

  • Jr. Member
  • **
  • Posts: 59
Re: Error dbf post
« Reply #2 on: June 14, 2021, 09:58:05 am »
Tank You

It the DBEdit3.SetFocus;  the probleme  :-\

 

TinyPortal © 2005-2018