On 7/24/05, Luiz Américo <[EMAIL PROTECTED]> wrote:
> As already commented in the code, the bookmarking done inside
> TDataset.DoInsertAppend is useless, not to say buggy.
> It makes 2 records to have the same bookmark data but this is not
> noticed because the bookmarkdata is set to the correct value after
> Post->Resync.
> 
> In TDBF, if the bookmark is get just after a insert call this bookmark
> will point to the previous record (see the attached example).
> 
> The patch remove this code and also refactory a if statement.
> 
> Unfortunately, after applying the patch if a bookmark is get after
> insert this bookmark points to the first record. This occurs because
> TDBF inits a buffer with BookMarkData=0 and BookMarkFlag=bfCurrent
> instead of bfInserted (this makes bookmarkavailable returns true)
> 
> As far as i can understand it seems that is not allowed to get a
> bookmark in a not posted record, is it?

You can bookmark at any time. But as the inserted record is not posted
yet, the bookmark will point to the current record in dataset.
Multiple users can insert records at same time.

> 
> BTW is necessary/correct the SetBookMarkFlag call (inside DoInsert) in
> this procedure ?
> 
> Luiz
> 
> 
> program testbookdbf;
> {$Mode ObjFpc}
> {$H+}
> 
> uses
>  sysutils,classes,db,dbf;
> var
>  Counter:Integer;
>  FDataset:TDbf;
>  Book0,Book1:TBookMarkStr;
> begin //Main
>  FDataSet:=TDbf.Create(nil);
>  with FDataSet do
>  begin
>    FilePathFull:=ExtractFilePath(ParamStr(0));
>    Tablename:='dbf_book.db';
>    if FileExists(FilePathFull+TableName) then
>      DeleteFile(FilePathFull+TableName);
>    if not FileExists(FilePathFull+TableName) then
>    begin
>      FieldDefs.Clear;
>      FieldDefs.Add('Int',ftInteger);
>      FieldDefs.Add('Str',ftString);
>      CreateTable;
>    end;
>    Open;
>    //add 2 records
> 
>    Insert;
>    FieldByName('Int').AsInteger:=-1;
>    FieldByName('Str').AsString:='minus';
>    Post;
> 
>    Insert;
>    FieldByName('Int').AsInteger:=0;
>    FieldByName('Str').AsString:='zero';
>    Post;
>    Book0:=Bookmark;
> 
>    Insert;
>    Book1:=Bookmark;
>    FieldByName('Int').AsInteger:=1;
>    FieldByName('Str').AsString:='one';
>    Post;
>    Book1:=Bookmark; //Comment this to get the error
> 
>    //Now go to bookmarks
>    Last;
>    writeln('Record before going to books: ',FieldByName('Int').AsInteger);
>    BookMark:=Book1;
>    writeln('Bookmark set to book1');
>    writeln('Current Record: ',FieldByName('Int').AsInteger);
>    BookMark:=Book0;
>    writeln('Bookmark set to book0');
>    writeln('Current Record: ',FieldByName('Int').AsInteger);
>    Free;
>  end;
> end.
> 
> _______________________________________________
> fpc-devel maillist  -  fpc-devel@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
> 
> 
> 
> 

This example is bad. See above.

Most datasets don't allow inserting records. Including TDbf.
If a dataset allow to insert records, and if the bookmark is the same
as record number, then the new record must have the same bookmark as
the old record.
Next records bookmarks must be changed.
If the record is appended, after DoInsert, follow
SetBookmarkFlag(ActiveBuffer,bfEOF);
It is ok i think.

Alex

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to