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
Solved

How long does a TDataset bookmark remain valid?

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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