Subject Re: [IBO] How open a dataset with only a Bookmark record?
Author Helen Borrie
At 11:29 AM 16/03/2003 +0000, you wrote:
>I have a bookmark for a lookup dataset. I want to use that bookmark
>for opening another dataset on the same record.
>I don't want to use something like:
>with qryCustomer do
>begin
> Open;
> Bookmark := workBookmarkString;
>end;
>because this way all the data is requested to the server and THEN the
>right record is located.
>I want instead have the behaviour the IBO Search has, i.e. return only
>the desired record, but I don't know how to make my workBookmarkString
>being used as a search criteria.
>In other words, I would like to have something like:
>with qryCustomer do
>begin
> Search;
> Bookmark := workBookmarkString;
>..First;
>end;
>
>that does not work.
>I don't want to fill the other field values for a search, since I need
>a generic solution and Bookmark produces always an unique key.
>How can I do?

KeyFields is a TIB_Row containing a TIB_Column object for each of the
KeyLinks columns of the row in the row buffer. Bookmark saves the current
row's KeyFields[n].Value properties as variants cast to strings, in a
semicolon-separated string, in the SQL column order.

So, if you want to apply the Bookmark values to the parameters of the
dataset's SQL generically, you could parse the values out an apply them to
the Params[n] - but only if your Params were in the same order as the SQL
order of the KeyLinks.

Instead of using Bookmark, you could extract KeyFields.FieldName and
KeyFields.Value out into a stringlist of the format FieldName=Value.

This gives you a way to get and store the key field names and values
generically, and independently of SQL order; then you can construct a
generic ParamByName assignment procedure by looping through the stringlist.

e.g., something along these lines:

procedure MyForm.GetSelectedRow (Dataset: TIB_Query);
var
StoredParms: TStringlist;
ii: integer;
begin
if Dataset.IsEmpty then
Exit;
StoredParms := TStringlist.Create;
try
with Dataset, StoredParms do
begin
for ii := 0 to KeyFields.ColumnCount - 1 do
Add(KeyFields[ii].FieldName + "=" + KeyFields.AsString);
Close;
for ii := 0 to Count - 1 do
ParamByName(Names[ii]).Value := Values[Names[ii]];
Open;
end;
finally
StoredParms.Free;
end;
end;

Helen