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.