Solved

How long does a TDataset bookmark remain valid?

Posted on 2009-05-14
3
1,018 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 37

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 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