Lazarus

Programming => LCL => Topic started by: Fabius on June 14, 2021, 09:11:52 am

Title: Error dbf post ( resolu )
Post by: Fabius 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;                   
Title: Re: Error dbf post
Post by: wp 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.
Title: Re: Error dbf post
Post by: Fabius on June 14, 2021, 09:58:05 am
Tank You

It the DBEdit3.SetFocus;  the probleme  :-\
TinyPortal © 2005-2018