Solved

How long does a TDataset bookmark remain valid?

Posted on 2009-05-14
3
1,025 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 38

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month10 days, 17 hours left to enroll

631 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