开发者

Delphi ADO + bookmarks

I am currently developing an application that uses databas开发者_JAVA技巧es dynamically.

meaning it is designed to work with any db, at any time, and any structures.

my concern is that I wish to "tag" or bookmark certain records, therefore I will require to use the Filter property to do some searching, and in the end, I wish to delete the filter, and be able to search through the bookmarked records...

however it seems the bookmark only work as long as the filter was set on that specified filter, so if I choose my second bookmarked item, i receive a totally different record than I expected, i.e. I did a filter, and bookmarked the first record, when I delete my filter and go to bookmark #1 I still just go to record nr. 1.

is there any other way to do this ? or is it required to do this in a different way ?

hope someone here has some mad genuine solution to this :)


A dataset in Delphi can bookmark only one record. TDataset.BookMark is the placeholder for that bookmarked record. A bookmark made while dataset was filtered is valid after the filter is gone too. So if you filter your dataset, and bookmark a record, then remove the filter, and go to your bookmark record, you should get to the same record.

If you are not sure if your bookmark is still valid, specially when your dataset is being edited; then you can use TDataset.BookmarkValid method to validate your bookmark.

If you want to have a list of bookmarks (not just one bookmarked record), then you have to save them in a list or array. In Delphi 2009 and newer versions, TBookMark data type is defined as TBytes. In previous versions, TBookMark is defined as string. So if you are using a version of Delphi prior to Delphi 2009, you can use an instance of TStringList to save your list of bookmarks. If you are using Delphi 2009 and above, you can use an instance of TList generic type (declared in Generics.Collections unit) to store the list of bookmarks.

If you are using DBGrid, DBGrid has a property called SelectedRows which is of type TBookMarkList. You can use it to save a list of bookmarks from selected rows in the grid. You need to enable multi-select in DBGrid's options.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜