Recent

Author Topic: Bookmarking  (Read 4572 times)

kapibara

  • Hero Member
  • *****
  • Posts: 610
Bookmarking
« on: May 16, 2017, 09:40:53 pm »
According to the doc's, GetBookmark, GotoBookmark and so on is deprecated and TBookmarkStr should be used together with the datasets Bookmark property. https://www.freepascal.org/docs-html/fcl/db/tdataset.bookmark.html

Are these errors because I use fpc 3.0 instead of 3.02 ?

Quote
uMain.pas(54,22) Error: Incompatible types: got "TBytes" expected "AnsiString"
uMain.pas(59,32) Error: Incompatible type for arg no. 1: Got "AnsiString", expected "TBytes"
Code: Pascal  [Select][+][-]
  1. var
  2.   bookmark: TBookmarkStr;
  3.  
  4. procedure TForm1.btnSetBookmarkClick(Sender: TObject);
  5. begin
  6.   bookmark:= qryItems.Bookmark;
  7. end;
  8.  
  9. procedure TForm1.btnGoToBookmarkClick(Sender: TObject);
  10. begin
  11.   qryItems.Bookmark := bookmark;
  12. end;
  13.  

« Last Edit: May 16, 2017, 10:10:58 pm by kapibara »
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Bookmarking
« Reply #1 on: May 16, 2017, 11:10:04 pm »
First, take a look on this other thread (TBookmark or TBookmarkStr — the confusion, May 06, 2013):

The documentation claims that TBookmark is deprecated in favour of TBookmarkStr, but, in the source, TBookmarkStr is the type which is marked deprecated.

The fpc 2.6.2 documentation (see: http://www.freepascal.org/docs-html/fcl/db/tbookmark.html) says that TBookmark is depracated:
Quote
TBookmark

Bookmark type (deprecated)
Further on the same page, you can read (bold by me):
Quote
TBookMark is the type used by the TDataset.SetBookMark method. It is an opaque type, and should not be used any more, it is superseded by the TBookmarkStr type.

However, the source of db unit (fpc 2.6.2) claims quite opposite:
Code: [Select]
  TBookmark = Pointer;
  TBookmarkStr = string deprecated 'TBookmarkStr will disappear in 2.6.3 in favour of TBookmark';

What is the actual status of these two types? Which one should be used?


TBookmark will stay for sure since it is D2009+ compatible.

Afaik this situation reflects the confusing situation with Delphi where first they steered people towards bookmarkstr (since string and thus managed), but that bit them when they changed the definition of the stringtype, and Embarcadero changed TBookmark to array of byte so that it was also autocleaned.

Currently, FPC 2.6.x leans towards bookmarkstr (older Delphis) and 2.7.x (more D2009+ like) will do both.

kapibara

  • Hero Member
  • *****
  • Posts: 610
Re: Bookmarking
« Reply #2 on: May 17, 2017, 02:30:03 pm »
Hilarous.  ::)

TBookmark is the way to go then.
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

GAN

  • Sr. Member
  • ****
  • Posts: 370
Re: Bookmarking
« Reply #3 on: May 17, 2017, 11:24:53 pm »
Code: Pascal  [Select][+][-]
  1.     for i:=0 to DBGrid1.SelectedRows.Count-1 do
  2.     with DBGrid1.DataSource.DataSet do
  3.     begin
  4.       GotoBookmark(pointer(DBGrid1.SelectedRows.Items[i]));
  5.       // do something
  6.     end;

Hi @kapibara I use this and works fine, but really don't know if can help you.
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

 

TinyPortal © 2005-2018