Subject | Re: [IBO] TIB_LookupEnh in search mode |
---|---|
Author | Geoff Worboys |
Post date | 2015-02-03T00:08:02Z |
Hi Marcin,
LookupEnh does special things with search buffers (not just
SearchBuffer but some of the internal "Adv" properties as
well) to make it work.
Basically the lookup requires the lookup source to have been
synchronised in order to get into a predictable state. I do
something a bit similar in one of my applications, where I am
loading a lookup with a default search value at start up.
The code required to make the lookup show the search looks
like this:
if tmpComp is TIB_CustomLookupEnh then
with tmpComp as TIB_CustomLookupEnh do
begin
if (LookupSource <> nil) and
(LookupSource.Dataset is TIB_BDataset) then
begin
if EditBeginModify then
begin
with TIB_BDataset(LookupSource.Dataset) do
Locate(KeyFields.Columns[0].FieldName, tmpStr, []);
EditEndModify;
end;
end;
end
where tmpStr has been set to the data field value (underlying
key value) required, and it assumes that the first keyfield of
the lookup dataset is the linking key value.
You may find that you have to set LookupDeactivation = false to
keep the lookup datasource active even when the control is not
focused.
Disclaimer: I also have some customisations in my copy of IBO
regarding searching, but I think the above works even without
them, it's been in my code for many years.
with search criteria. When the user hits the search button I
do this (amongst other things):
// Ensure any parameters are updated first
DataLink.Dataset.UpdateData;
// We have to save the search criteria before executing the
// search because lookup states (and saved search data) can
// change as a result of the search.
strs := TStringList.Create;
DataLink.Dataset.WriteSearch(strs);
FLastSearchData := Trim(strs.Text);
DataLink.Dataset.First; // execute the search
...
finally
FreeAndNil(strs)
Once you have a copy of the search criteria (saved just before
search is executed) you can do what you want in terms checking
what's in there and comparing to prior searches and so on.
I hope this helps a little.
--
Geoff Worboys
Telesis Computing Pty Ltd
> In my application I have a routine that puts current fieldSearch state with lookups is always a bit ... interesting.
> value into search criteria and post the dataset's search
> state.
> For TIB_LookupEnh controls it looks like this:
LookupEnh does special things with search buffers (not just
SearchBuffer but some of the internal "Adv" properties as
well) to make it work.
Basically the lookup requires the lookup source to have been
synchronised in order to get into a predictable state. I do
something a bit similar in one of my applications, where I am
loading a lookup with a default search value at start up.
The code required to make the lookup show the search looks
like this:
if tmpComp is TIB_CustomLookupEnh then
with tmpComp as TIB_CustomLookupEnh do
begin
if (LookupSource <> nil) and
(LookupSource.Dataset is TIB_BDataset) then
begin
if EditBeginModify then
begin
with TIB_BDataset(LookupSource.Dataset) do
Locate(KeyFields.Columns[0].FieldName, tmpStr, []);
EditEndModify;
end;
end;
end
where tmpStr has been set to the data field value (underlying
key value) required, and it assumes that the first keyfield of
the lookup dataset is the linking key value.
You may find that you have to set LookupDeactivation = false to
keep the lookup datasource active even when the control is not
focused.
Disclaimer: I also have some customisations in my copy of IBO
regarding searching, but I think the above works even without
them, it's been in my code for many years.
> Another question that raises here is: Is there a way to checkI'm not sure if this helps, but one my application forms plays
> in some dataset's event (i.e after post when posted state was
> dssSearch) that any search criteria were set? I've tried:
> DataSet.SearchCriteria.Count
with search criteria. When the user hits the search button I
do this (amongst other things):
// Ensure any parameters are updated first
DataLink.Dataset.UpdateData;
// We have to save the search criteria before executing the
// search because lookup states (and saved search data) can
// change as a result of the search.
strs := TStringList.Create;
DataLink.Dataset.WriteSearch(strs);
FLastSearchData := Trim(strs.Text);
DataLink.Dataset.First; // execute the search
...
finally
FreeAndNil(strs)
Once you have a copy of the search criteria (saved just before
search is executed) you can do what you want in terms checking
what's in there and comparing to prior searches and so on.
I hope this helps a little.
--
Geoff Worboys
Telesis Computing Pty Ltd