Filtering Records Based On Bookmarks

From RAD Studio
Jump to: navigation, search

Go Up to Connecting an ADO Dataset to a Data Store


ADO datasets support the common dataset feature of using bookmarks to mark and return to specific records. Like other datasets, ADO datasets let you use filters to limit the available records in the dataset. ADO datasets provide an additional feature that combines these two common dataset features: the ability to filter on a set of records identified by bookmarks.

To filter on a set of bookmarks:

  1. Use the Bookmark method to mark the records you want to include in the filtered dataset.
  2. Call the FilterOnBookmarks method to filter the dataset so that only the bookmarked records appear.

This process is illustrated below:

procedure TForm1.Button1Click(Sender: TObject);
var
  BM1, BM2: TBookmark;
begin
  with ADODataSet1 do 
  begin
    BM1 := Bookmark;
    BMList.Add(BM1);

    MoveBy(3);

    BM2 := Bookmark;
    BMList.Add(BM2);

    FilterOnBookmarks([BM1, BM2]);
  end;
end;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TBookmark BM1, BM2;

    BM1 = ADODataSet1->Bookmark;
    BMList->Add(BM1);

    ADODataSet1->MoveBy(3);

    BM2 = ADODataSet1->Bookmark;
    BMList->Add(BM2);

    ADODataSet1->FilterOnBookmarks(ARRAYOFCONST((BM1,BM2)));
}

Note that the previous example also adds the bookmarks to a list object (TList<TBookmark>) named BMList. This is necessary so that the application can later free the bookmarks (FreeBookmark) when they are no longer needed.

See Also