Menu

#92 tdbf 7.01 adds extra record on first append with memo

Win32_only
open
nobody
None
5
2023-03-14
2018-01-06
No

When I create a new record with a lot of fields (the very first record in an empty table), then immediately edit the record and assign strings from a memo control via blobstream and post it, a 2nd record is appended after the first one with fields arbitrarily empty; only happens when the table is empty and doing this on the first record though. Running Windows 10 64 bit and Delphi XE 10.2 and compiling as Win32. The NOTES field is the Nil before PNotes below; Table Level is 25 and open mode is omAutoCreate.

Var
BlobField: TField;
BS: TStream;

DM.DSUnRouted1.DataSet.AppendRecord([TempP, CNum, TempSC, RtNum,
WONum, Now, ImpStat, CFN, False,
CName, CAddr, CCity, CState, CZip,
'', '', CInq, MoPer, TempTN, TempWa,
TempGI, Nil, PNotes, MPY, BName, LocRt,
PDFFile, TempUL, TempEM]
);
If Memo4.Lines.Count > 0 Then
Begin
DM.DSUnRouted1.DataSet.Edit;
BlobField := DM.DSUnRouted1.DataSet.FieldByName('NOTES');
BS := DM.DSUnRouted1.DataSet.CreateBlobStream(BlobField, bmWrite);
Memo4.Lines.SavetoStream(BS);
DM.DSUnRouted1.DataSet.Post;
BS.Free;
End;

2 Attachments

Discussion

  • Paul Baker

    Paul Baker - 2018-01-09

    Would you mind making this example the simplest you can?

    You should be able to reproduce it with a console application with one file, the DPR, that creates the table, etc.

     
  • Alan Sandige

    Alan Sandige - 2018-01-09

    Here is a really basic program to add 10 records. If you examine the database with MyDBF you'll see the 2nd record has invalid data. When you run the program, it intentionally filters the bad record out otherwise it throws errors. but you'll also notice that the physical record numbers (before each append) are -1, 2, 0, 0... maybe this will help.

     
  • Alan Sandige

    Alan Sandige - 2018-01-10

    So I found if you use LAST on the dataset after you AppendRecord, but before commiting the lines to the Memo field, everything works fine.

     
    • Paul Baker

      Paul Baker - 2018-01-11

      I simplified your example, demonstrating what I was suggesting - a console application with one file, the DPR.

      Here's how I'd request that you simplify it further, so that anyone can reproduce it just by pasting this code in any Delphi version and running it.
      * Add verification code that raises an exception if the problem occurs.
      * Create the files we need at runtime using TDbf.CreateTable(), if possible, instead of depending on the test.dbf and test.fpt files you provided. It may not be possible if there is something odd about the files that is part of the problem.

      program bug92;
      
      uses
        Classes, DB, SysUtils,
        dbf;
      
      var
        I: Integer;
        Dbf1: TDbf;
        S: AnsiString;
      begin
        Dbf1 := TDbf.Create(nil);
        try
          Dbf1.TableName := 'test.dbf';
          Dbf1.Exclusive := True;
          Dbf1.Open;
          Dbf1.Zap;
          for I := 1 to 10 do
          begin
            Dbf1.AppendRecord(['This is record ' + IntToStr(Dbf1.PhysicalRecNo), Dbf1.PhysicalRecNo, Now, nil, (Dbf1.PhysicalRecNo mod 2) = 0, I + 0.125]);
            Dbf1.Edit;
            try
              with Dbf1.CreateBlobStream(Dbf1.FieldByName('MEMO'), bmWrite) do
              try
                S := 'Hello, World!';
                Write(PAnsiChar(S)^, Length(S));
              finally
                Free;
              end;
              Dbf1.Post;
            except
              Dbf1.Cancel;
              raise;
            end;
          end;
        finally
          Dbf1.Free;
        end;
      end.
      
       

      Last edit: Paul Baker 2023-03-14
  • Alan Sandige

    Alan Sandige - 2018-01-11

    Thanks for the example, any suggestions about resolving the problem on the component level?

     
  • Alan Sandige

    Alan Sandige - 2018-02-07

    A work around is you can use .Last after you append the record, but before you update the memo field; even though it is supposed to put the pointer on the new record it doesn't in this case so the .Last procedure forces it to do so. Any fix coming soon so I don't have to do this?

     
  • Alan Sandige

    Alan Sandige - 2018-03-07

    Update, after working with it more, I found that the memo data is written to many of the fields.

     
  • Alan Sandige

    Alan Sandige - 2018-03-09

    My bad guys, the .Last fix does work, I just had a bug in my code...still it would be nice if they could encorporate a built-in change ;)

     
  • Paul Baker

    Paul Baker - 2023-03-14

    Can you reproduce this in revision 843? I fixed a memo bug in revision 804.

     

    Last edit: Paul Baker 2023-03-14

Log in to post a comment.

MongoDB Logo MongoDB