Subject Re: [IBO] Multi select
Author Helen Borrie
At 12:21 AM 27/10/2006, you wrote:
>Hi,
>
>I want to use multi-select at an IB_Grid, but I'm a little confused.
>
>I read about SelectedBookmarks, and I'm trying to use it like this:
>
> qrMyQuery.SelectedBookmarks(s);
>
>S is an StringList var.
>qrMyQuery has a PrimaryKey.
>
>Problems:
>
>- If I have only one record selected, S receive nothing, stays empty.
>If I have two or more records, S receives one record less the total.
>Eg. 5 records selected, and S receives only 4. What I'm doing wrong?

What are you reading to get the count of the bookmarks? S.Count? or
are you iterating through the strings, perhaps forgetting that the
first one is S[0], not S[1] ?

Could there be some confusion here, in that the inherited Row
property of the TCustomGrid is not the same as the RowNum of the
dataset? The TIB_Grid.GridRow property is used for matching up the
grid row with the dataset row...


>- The stringList, is receiving something like this: 00008C710000 But,
>what is this?

It is a value that uniquely identifies a record as it was
fetched. If you have KeyLinks set, it is made from the primary key
value and (I think) the length of the key value. If no KeyLinks are
set, it will be made from the value of the DB_KEY and the validity of
the bookmarks is good only for the current transaction, i.e. not very useful.

>It seams a hexa value or something like that. But the primary is an
>integer field.

Correct. Bookmarks are extracted from the Rowdata of the dataset's
KeyFields structure and the data's length, providing a unique number
that is converted to a hex string.

>How can I use the content of S in a Select statement?

Directly, not at all. It is a client-side mechanism. The purpose of
the bookmark is to capture the "uniqueness" attribute of the row in
the context of the buffers. Provided you have KeyLinks properly set
in each dataset, you can use the bookmark of one dataset to locate a
row in another dataset that has a matching bookmark, or to locate the
"same" row in the original dataset. Bookmarks derived from
properly-set KeyLinks will survive a commit.

If you don't have KeyLinks set, the stability of bookmarks across
transactions cannot be guaranteed.

You can iterate through your SelectedBookmarks array and use the
Bookmark reference to find each record and retrieve any actual data
that you want to use, e.g. to pass as a value to a parameterised statement.

HTH

Helen