Solved

How long does a TDataset bookmark remain valid?

Posted on 2009-05-14
3
1,012 Views
Last Modified: 2013-11-23
I have code like below in a project I'm working.

Personally, I do not use bookmarks much  except to reposition a dataset where I only moved the cursor position (to create a listing, fill a string list, etc). If I Refresh, update (especially when a filter can make the record invisible), refetch (Close/Open) or any operation that modifies the data in the dataset, I don't use bookmarks. I prefer to Locate on the primary key (using a TClientDataset, of course) or requery modifying the parameters.

Until when is a bookmark valid? Until a Refresh? Until a Close/Open is done to refetch data? Where does the safe zone end?

Consider in the answer I'm using TClientDataset with a TSQLQuery (DbExpress).
procedure TForm.EditBtnClick(Sender:TObject);

begin

  // Mark is form variable. It's private

  Mark = cdsMain.GetBookmark;

  // blabalbal

  .

  .   

  .

end;
 

procedure TForm.OkBtnClick(Sender:TObject);

var  

  mistakes: Integer;

begin

  //Validation stuff and transaction control

  //removed to not clutter the code

  If cdsMain.ChangeCount <> 0 then 

    mistakes := cdsMain.AppyUpdates(-1); 

  cdsMain.Refresh;

  try

    cdsMain.GotoBookmark(Mark);

    // Yes, I know I would have to call FreeBookmark

    // but I'm just reproducing 

  except

    cdsMain.First;

  end;

end;

Open in new window

0
Comment
Question by:Delphian
3 Comments
 
LVL 26

Accepted Solution

by:
EddieShipman earned 250 total points
ID: 24390400
Compiled from two posts on the CodeGear forums:

You can not retain or reuse TBookMarks once a TDataSet has been closed and reopened. A TBookmark is a reference
to a record pointer not the data contained within the record. TBookmark is not guaranteed to be valid after the
dataset is closed in any case (IBX, BDE or other dataset). It is documented this way. The only way to do
this is reliably is to store off a key value that you can re lookup the record in the new result set.
0
 
LVL 36

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 200 total points
ID: 24403900
A bookmark is actually just a offset to the n-th record.
if you have 1 recordset, take a bookmark and use that on a other (same size record) recordset, you'll end up on the same n-th record.

so it's valid as long as dataset.BookmarkValid(Bookie) = True

as EddieShipman says ... use the primary key
0
 
LVL 4

Author Comment

by:Delphian
ID: 24424968
Interesting results. Have you tried that specifically with TClientDatasets??
After a little research on Db.pas, I saw that all *Bookmark methods are abstract,
so the descendants are responsible for the implementation.


0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now