Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add this "foPartialCompare" where? 2

Status
Not open for further replies.

CliffClimber

Technical User
Sep 18, 2003
16
US
Hi! The filters for my lookup program are hand coded. I understand that if they were defined in the Object Inspector I could add to the FilterOptions to include foPartialCompare.
I wish to allow a " * " wild card in the searches.
What wording in the hand coding do I look for so that I may add the foPartialCompare? Thanks!
 
I don't know if I understand your question correctly, but I'll take a shot at it...By "hand coded" I take it to mean that you're using the OnFilterRecords event handler instead of the Filter propery of the dataset.

If the search string contains an asterisk, then you find out where the asterisk is - beginning or end (I wouldn't recommend allowing it in the middle of the search string.) If the asterisk is at the end you could do this:
Code:
sComp := copy(SearchString, 1, length(SearchString) - 1);  //take out asterisk
Accept := pos(sComp, dataset.FieldByName('MyField').AsString) = 1;

if the asterisk is at the beginning, you could do something like this:
Code:
sComp := copy(SearchString, 2, length(SearchString));
Accept := pos(sComp,dataset.FieldByName('MyField').AsString) = (length(dataset.FieldByName('MyField').AsString) - length(sComp) + 1);

I would probably set the comparison string (sComp) prior to telling the dataset to filter so that it only gets set once.

-D
 
Thanks, hilfy, I'll try to explain a little differently.
I wish to use a wild card in my lookup search, currently it will not accept the " * " as valid.
I may be offtrack (common) but the book says to add foPartialCompare to FilterOptions which will allow "*" as a valid search character.
I interpreted what you outlined above as allowing a search for the existance of an asterik in the data fields.
This may still not have explained any better :) ,Thankyou!
 
I guess the question is, how are you "setting" your filter. Are you using the Filter parameter of the dataset or the OnFilterRecord event handler?

If you're using the Filter paramter, then the FilterOptions should work. However, I'm using Delphi 5 and I don't have the "foPartialCompare" value, the one that's there is "foNoPartialCompare" which does just the opposite of what you want.

If you're using the OnFilterRecord event handler, you'll have to use code like I gave you in my previous post.

-D
 
I'll study it further and try your scripts. Thanks for your responses! Cliff
 
Borland introduced some string handling routines which make some common operations a little easier. Perhaps not everyone is familiar with them?

From hilfy's example code above:

I find the following is simpler to understand if the asterisk is at the end of the string:
Code:
sComp := LeftStr (SearchString, length(SearchString)-1);  //take out asterisk
Accept := AnsiStartsStr ( sComp, dataset.FieldByName('MyField').AsString) );
and the following when the asterisk is at the start of the string:
Code:
sComp := RightStr (SearchString, length(SearchString)-1);  //take out asterisk
Accept := AnsiEndsStr ( sComp, dataset.FieldByName('MyField').AsString) );
The functions LeftStr, RightStr, AnsiStartsStr, AnsiEndsStr are defined in the StrUtils unit (of Delphi 7).


Andrew
Hampshire, UK
 
Thanks towerbase, it will be tommorrow before I can get back to this part of the project, and then am sure things will work! Cliff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top