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;
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.
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.
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.
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 thetest.dbfandtest.fptfiles you provided. It may not be possible if there is something odd about the files that is part of the problem.Last edit: Paul Baker 2023-03-14
Thanks for the example, any suggestions about resolving the problem on the component level?
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?
Update, after working with it more, I found that the memo data is written to many of the fields.
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 ;)
Can you reproduce this in revision 843? I fixed a memo bug in revision 804.
Last edit: Paul Baker 2023-03-14