RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TDataSet.GetBookmark Method

Allocates a bookmark for the active record in the dataset.

Pascal
function GetBookmark: TBookmark; virtual;
C++
virtual __fastcall TBookmark GetBookmark();

Call GetBookmark to establish a bookmark for the active record in the dataset. Establishing a bookmark for a record enables a dataset to return to that record at any time while the bookmark exists. 

GetBookmark requires that a variable for the bookmark (for Delphi, of type TBookmark) already be declared in the application. Use GetBookmark to assign a value to the variable. This value can then be referenced by subsequent calls to GotoBookmark and FreeBookmark

Applications that create bookmarks with GetBookmark must subsequently release the system resource allocated to them by calling FreeBookmark when the bookmarks are no longer needed.

Note: GetBookmark relies on a protected method to obtain the bookmark value. TDataSet descendants implement this method to provide their own type of bookmark support. Unidirectional datasets do not support bookmarks, and so do not return a meaningful value.
 

Delphi Examples: 

 

{
This example uses a button to copy the value of a field in
the previous record into the corresponding field in the
current record.
}
procedure TForm1.Button1Click(Sender: TObject);
var
   SavePlace: TBookmark;
   PrevValue: Variant;
begin
   with Customers do
   begin
    { get a bookmark so that we can return to the same record }
    SavePlace := GetBookmark;
    try
      { move to prior record}
      FindPrior; 
      { get the value }
      PrevValue := Fields[1].Value;
      {Move back to the bookmark
      this may not be the next record anymore 
      if something else is changing the dataset asynchronously }
      GotoBookmark(SavePlace);
      { Set the value }
      Edit;
      Fields[1].Value := PrevValue;
      { Free the bookmark }
    finally
      FreeBookmark(SavePlace);
    end;
  end;
end;

{
To ensure that the button is disabled when there is no
previous record, the OnDataChange event of the DataSource
detects when the user moves to the beginning of file (BOF
property becomes true), and disables the button.  Detection
occurs on scrolling and editing, not selection with the mouse.
} 
procedure TForm1.DS2DataChange(Sender: TObject; Field: TField);
begin
  if Customers.Bof then
    Button1.Enabled := False
  else
    Button1.Enabled := True;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!