Recent

Author Topic: Dbf Append , Error ?  (Read 2519 times)

Fabius

  • New Member
  • *
  • Posts: 40
Dbf Append , Error ?
« on: June 16, 2021, 05:18:48 pm »



Good morning all :)

I have an error message during execution ( compile OK )
dataset error, not in insert or edit mode

I tried with Append and insert

i still have an error

According to you or am I wrong?

Thank for Help  ;D

My Code

 lignesDeSaisie = Tdbf

On button command
Juste this

       Try
        lignesDeSaisie.Append;
        /////lignesDeSaisie.Insert;

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

        lignesDeSaisie.Post;
        finally

        end;


 

winni

  • Hero Member
  • *****
  • Posts: 2524
Re: Dbf Append , Error ?
« Reply #1 on: June 16, 2021, 06:03:32 pm »
Hi

You did not set the DB in the edit mode.

After insert or append you have to do

Code: Pascal  [Select][+][-]
  1. lignesDeSaisie.Edit;
  2.  


And please: use code formatting for your code!

Winni

Fabius

  • New Member
  • *
  • Posts: 40
Re: Dbf Append , Error ?
« Reply #2 on: June 16, 2021, 06:37:31 pm »
Ok , Thank  ;D , I test

Fabius

  • New Member
  • *
  • Posts: 40
Re: Dbf Append , Error ?
« Reply #3 on: June 16, 2021, 06:41:28 pm »


I have tested


        lignesDeSaisie.Append;
        ///lignesDeSaisie.Edit;
        lignesDeSaisie.FieldByName('compte').AsString := Form1.Xcomptes.FieldByName('compte').AsString;
        lignesDeSaisie.FieldByName('label').AsString := Form1.Xcomptes.FieldByName('label').AsString;
        lignesDeSaisie.FieldByName('credit').AsFloat := 0;
        lignesDeSaisie.FieldByName('debit').AsFloat := 0;
        ///lignesDeSaisie.Post;   


If I del the line post , it's OK

???

wp

  • Hero Member
  • *****
  • Posts: 8584
Re: Dbf Append , Error ?
« Reply #4 on: June 16, 2021, 09:27:38 pm »
The code which you show is correct. When it is not working then there must be something in your code which must put the dataset back into browse mode before you call dataset.Post. Convince yourself by means of the attached demo which simply does the same as in your code.

Make a backup of your project and remove all unnecessary parts. Usually you can find the issue this way by yourself. If not, pack the .pas, lfm, lpr, lpi and dbf files into a common zip which you can upload here.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018