TBookMark problem with Delphi 2010 and TList

Going on with the big rewrite of code from Delphi 2007 to 2010 (most of it an adaptation more than a rewrite), but we've found some hidden problems as a result of changes appeared in the new version. One of the flaws was shown while I was working with TBookMark class, trying to position a dataset in a given bookmark. With the help of the Embarcadero Forum, we achieved a solution by using "generics" (I'm preparing a post with generics in Delphi 2010) because the TBookMark is now of type TBytes.
Then, the solution would be something similar to this:
uses
    Generics.Collections;

var
    bookmarkList: TList<TBookmark>; //The same as TList<SysUtils.TBytes>

//Adding the bookmark
bookmarkList.Add(cds.GetBookmark);

//We don't need the TBookMark cast
procedure TForm1.GotoBkMarksClick(Sender: TObject);
var
    Cnt: Integer;
begin
    for Cnt := 0 to Pred(BookmarkList.Count) do
    begin
        if DataSet.BookmarkValid(BookmarkList[Cnt]) then
        begin
            DataSet.GotoBookmark(BookmarkList[Cnt]);
            ShowMessage(DataSet.FieldByName('Id').AsString);
       end;
    end;
end;
You need to take into account that every project is different and the use of the TBookMark can differ from one project to another.

Comments

Popular Posts