Subject | Re: [IBO] Multi select |
---|---|
Author | Andrei Luís |
Post date | 2006-10-27T12:49:53Z |
Helen, thanks for your interest and your effort.
2006/10/26, Helen Borrie <helebor@...>:
that the record where the cursor is set, it is already selected. But
this is not true, right? I need to selected it with Ctrl + Click or
Shift.
As far as I understand, I have to do something like that to retrieve
the selected records:
myQuery1 = TIB_Query
s = TStringList
int = Integer
myQuery1.SQL := 'Select * from customers';
myQuery1.KeyLinks := 'customers.record_id';
myQuery1.SelectedBookmarks(S);
for int := 0 to S.Count-1 do
begin
myQuery1.Bookmark := S[int];
ShowMessage(myQuery1.FieldByName('Name').asString);
end;
Is that correct?
This is just an example. What I really need is to select some records
in a Grid, and then process them inserting in another table.
[]s
Andrei
Win XP Pro + D4 Pro + FB 1.5.2 + IBO 4.6B
2006/10/26, Helen Borrie <helebor@...>:
> At 12:21 AM 27/10/2006, you wrote:I was using S[0], S[1] ... I discovered what is happening: I assumed
> >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] ?
that the record where the cursor is set, it is already selected. But
this is not true, right? I need to selected it with Ctrl + Click or
Shift.
> Could there be some confusion here, in that the inherited RowTIB_Grid.Row is equal to TIB_Query.RowNum.
> property of the TCustomGrid is not the same as the RowNum of the
> dataset?
> >- The stringList, is receiving something like this: 00008C710000 But,I have KeyLinks set with primary key like this: customer.record_id
> >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.
As far as I understand, I have to do something like that to retrieve
the selected records:
myQuery1 = TIB_Query
s = TStringList
int = Integer
myQuery1.SQL := 'Select * from customers';
myQuery1.KeyLinks := 'customers.record_id';
myQuery1.SelectedBookmarks(S);
for int := 0 to S.Count-1 do
begin
myQuery1.Bookmark := S[int];
ShowMessage(myQuery1.FieldByName('Name').asString);
end;
Is that correct?
This is just an example. What I really need is to select some records
in a Grid, and then process them inserting in another table.
[]s
Andrei
Win XP Pro + D4 Pro + FB 1.5.2 + IBO 4.6B