Menu

#112 in memory table with memo fields

Win32/Linux
open
5
2024-10-08
2024-10-05
Carlo
No

Hello
I have a memory table containing some memo fields. (table.Storage := stoMemory).
It gives me a "divide by zero" error when I try to add a record.
If I set table.Storage := stoFile, everything works fine.

The error is raised in
unit dbf_memo;
procedure TMemoFile.WriteMemo(var BlockNo: Integer; ReadSize: Integer; Src: TStream);
because RecordSize=0, the test
if ((bytesBefore + Src.Size + bytesAfter + RecordSize-1) div RecordSize) <= ((ReadSize + RecordSize-1) div RecordSize) then........ raise the error.

I've modified the code in this way:

** if RecordSize = 0 then
boolVar := ((bytesBefore + Src.Size + bytesAfter + RecordSize - 1)) <= ((ReadSize + RecordSize - 1))
else
boolVar := ((bytesBefore + Src.Size + bytesAfter + RecordSize - 1) div RecordSize) <= ((ReadSize + RecordSize - 1) div RecordSize);
if boolVar then..........**

and in my case it works.

I'm submitting this correction, in case you would like to use it to correct the code.

Kind regards.

Discussion

  • Paul Baker

    Paul Baker - 2024-10-06

    Can you provide a short program that reproduces this? I see the concern with the code, but if RecordSize is 0, there is a bigger issue.

     
  • Carlo

    Carlo - 2024-10-07

    Hello
    This is the code that raises the error when I post the new record:

    ~~~
    constructor TmyClass.create;
    begin
    FTable := TDbf.create(nil);
    FTable.TableName := 'Table.dbf';
    FTable.Storage := stoMemory;
    With FTable do
    begin
    Close;
    TableLevel := 7;
    Exclusive := True;
    with FieldDefs do
    begin
    clear;
    add('tag', ftString, 80, False);
    add('FIELD1', ftMemo, 0, False);
    add('FIELD2', ftMemo, 0, False);
    end;
    CreateTable;
    Open;
    AddIndex('idxByTag', 'tag', [ixPrimary, ixUnique]);
    end;
    FTable.append;
    FTable.FieldByName('TAG').AsString := 'xx';
    FTable.FieldByName('FIELD1').AsString := 'yyyyyyyyyyyy yyyyyyyyyyyyyyyyy yyyyyyyyyyyyyyyy';
    FTable.FieldByName('FIELD2').AsString := 'zzzzzzzzzz zzzzzzzzzzzzzzzzz zzzzzzzzz';
    FTable.Post;
    end;
    ~~~**

    The modification that I've described in my previus post doesn't work!

    thank you for your reply

     
    • Paul Baker

      Paul Baker - 2024-10-08

      I can reproduce it using this code.

      Unfortunately, it looks like when you open a table, it can only open the associated memo if it actually exists as a file. I don't think you'll be able to solve it with a minor change like you suggested.

      We would have to add a feature, and I don't know who has time to do it.

      Maybe there is a different way you can achieve what you need?

       
  • Carlo

    Carlo - 2024-10-08

    I agree with you about the impossibility of solving the problem with small changes.
    The change I made avoids division by zero but after this operation nothing works anymore.
    Anyway, thanks for your help

     

Log in to post a comment.

MongoDB Logo MongoDB