Norm-al
asked on
Ignoring case in Delphi field
I'm using the following code in a form that lets users search multiple fields through delphi's filters to find certain records and display them in a grid.
sContractor := '%' + cbContractor.Text + '%';
sStreetName := '%' + edStreet_Name.Text + '%';
sBuyer := '%' + edBuyer.Text + '%';
with gvresults.DataController.F ilter do begin
Clear;
Root.BoolOperatorKind := fboAND;
if cbContractor.Text <> '' then AddItem(Root,gvResultsCont ractor, foLike, sContractor , sContractor);
if edStreet_Name.Text <> '' then AddItem(Root,gvResultsStre et_Name, foLike, sStreetName , sStreetName);
if edBuyer.Text <> '' then AddItem(Root,gvResultsBuye r, foLike, sBuyer , sBuyer);
So far I've worked out how to include 'wildcards' in the search, but I haven't worked out how to make the fields ignore the case of the character string entered by user--I assume it needs to be done when the variables are declared though...
sContractor := '%' + cbContractor.Text + '%';
sStreetName := '%' + edStreet_Name.Text + '%';
sBuyer := '%' + edBuyer.Text + '%';
with gvresults.DataController.F
Clear;
Root.BoolOperatorKind := fboAND;
if cbContractor.Text <> '' then AddItem(Root,gvResultsCont
if edStreet_Name.Text <> '' then AddItem(Root,gvResultsStre
if edBuyer.Text <> '' then AddItem(Root,gvResultsBuye
So far I've worked out how to include 'wildcards' in the search, but I haven't worked out how to make the fields ignore the case of the character string entered by user--I assume it needs to be done when the variables are declared though...
ASKER
Hi Cesar.
Where exactly would I put that code in for it to work? I've tried a few ways but none seem to work (though it may be a syntax problem on my part).
Thanks.
Where exactly would I put that code in for it to work? I've tried a few ways but none seem to work (though it may be a syntax problem on my part).
Thanks.
Hi, for a start you need to convert your compare variables to uppercase
sContractor := '%' + UpperCase(cbContractor.Tex t) + '%';
sStreetName := '%' + UpperCase(edStreet_Name.Te xt) + '%';
sBuyer := '%' + UpperCase(edBuyer.Text) + '%';
with gvresults.DataController.F ilter do begin
Clear;
Root.BoolOperatorKind := fboAND;
(gvResultsX where do you build it?)
if cbContractor.Text <> '' then AddItem(Root,gvResultsCont ractor, foLike, sContractor , sContractor);
if edStreet_Name.Text <> '' then AddItem(Root,gvResultsStre et_Name, foLike, sStreetName , sStreetName);
if edBuyer.Text <> '' then AddItem(Root,gvResultsBuye r, foLike, sBuyer , sBuyer);
sContractor := '%' + UpperCase(cbContractor.Tex
sStreetName := '%' + UpperCase(edStreet_Name.Te
sBuyer := '%' + UpperCase(edBuyer.Text) + '%';
with gvresults.DataController.F
Clear;
Root.BoolOperatorKind := fboAND;
(gvResultsX where do you build it?)
if cbContractor.Text <> '' then AddItem(Root,gvResultsCont
if edStreet_Name.Text <> '' then AddItem(Root,gvResultsStre
if edBuyer.Text <> '' then AddItem(Root,gvResultsBuye
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ah, that's even better! nice one
easiest way is to uppercase() both sides or upper() or use ansicompare with the ignore case option
looking at your sourcecode you're using the Developer Express grid.
In that case briangochnauer answer should work (if you remove the space) if you put it in (for instance) the OnCreate of the form.
gvresults.DataController.F ilter.Opti ons := [fcoCaseInsensitive];
You can also set it in during design in the object inspector.
In that case briangochnauer answer should work (if you remove the space) if you put it in (for instance) the OnCreate of the form.
gvresults.DataController.F
You can also set it in during design in the object inspector.
Hi,
As GeneralTackett says, you need to compare it on both sides as follows.
UpperCase(sContractor) := '%' + UpperCase(cbContractor.Tex t) + '%';
UpperCase(sStreetName) := '%' + UpperCase(edStreet_Name.Te xt) + '%';
UpperCase(sBuyer) := '%' + UpperCase(edBuyer.Text) + '%';
with regards
Padmaja.
As GeneralTackett says, you need to compare it on both sides as follows.
UpperCase(sContractor) := '%' + UpperCase(cbContractor.Tex
UpperCase(sStreetName) := '%' + UpperCase(edStreet_Name.Te
UpperCase(sBuyer) := '%' + UpperCase(edBuyer.Text) + '%';
with regards
Padmaja.
Hi
Sorry, need to compare it on both sides with if statement.
with regards,
Padmaja.
Sorry, need to compare it on both sides with if statement.
with regards,
Padmaja.
saravananvg, the code you posted is not actually correct, what Prec94513 is doing there, he is assigning the text on cbContractor to sContractor, so making an UpperCase(sContractor) := '%' .... does not works...
you could change the ands for ors if you like.. .or any combination given that you put parenthesis around the sections accordingly...
if ( (UpperCase(sContractor) ) =( '%' + UpperCase(cbContractor.Tex t) + '%')) and
( UpperCase(sStreetName) )=( '%' + UpperCase(edStreet_Name.Te xt) + '%')) and
( UpperCase(sBuyer))=( '%' + UpperCase(edBuyer.Text) + '%'))
then begin
.....
end
else begin
...
end;
if ( (UpperCase(sContractor) ) =( '%' + UpperCase(cbContractor.Tex
( UpperCase(sStreetName) )=( '%' + UpperCase(edStreet_Name.Te
( UpperCase(sBuyer))=( '%' + UpperCase(edBuyer.Text) + '%'))
then begin
.....
end
else begin
...
end;
The original poster is using the Developer Express Quantum Grid as you can see by the '.DataController.Filter' part of the code (google it and you'll see). If you are not familiar with that component chances are that all of your well ment advice is actually making things more difficult, as the filter of that grid has a special property (fcoCaseInsensitive) to ignore case in the filter statement.
Setting that property will solve all the OPs problems.
From the helpfile:
Unit
cxFilter
TcxFilterCriteriaOption = (fcoCaseInsensitive, fcoShowOperatorDescription , fcoSoftNull, fcoSoftCompare, fcoIgnoreNull);
Description
The TcxFilterCriteriaOption represents an enumeration of values that control data filtering. The following table describes the possible options. Filter options are supported by the TcxFilterCriteria.Options property.
Value Meaning
fcoCaseInsensitive Specifies whether filtering is case sensitive. When this flag is active in the TcxFilterCriteria.Options property, filtering does not distinguish upper and lowercase characters.
fcoShowOperatorDescription If set, replaces operator symbols with their corresponding text representation.For instance, the ‘=’ operator is replaced with the ‘equals’ string. Operator descriptions are defined in the cxFilterConsts.pas source file.
fcoSoftNull If set, empty strings are considered as NULL values when comparing.
fcoSoftCompare If set, no exception is thrown when comparing values of incompatible types.
fcoIgnoreNull If set, NULL values are ignored when comparing and are excluded from the filtered results.
Setting that property will solve all the OPs problems.
From the helpfile:
Unit
cxFilter
TcxFilterCriteriaOption = (fcoCaseInsensitive, fcoShowOperatorDescription
Description
The TcxFilterCriteriaOption represents an enumeration of values that control data filtering. The following table describes the possible options. Filter options are supported by the TcxFilterCriteria.Options property.
Value Meaning
fcoCaseInsensitive Specifies whether filtering is case sensitive. When this flag is active in the TcxFilterCriteria.Options property, filtering does not distinguish upper and lowercase characters.
fcoShowOperatorDescription
fcoSoftNull If set, empty strings are considered as NULL values when comparing.
fcoSoftCompare If set, no exception is thrown when comparing values of incompatible types.
fcoIgnoreNull If set, NULL values are ignored when comparing and are excluded from the filtered results.
The author of this question has not been involved.??
Hope this works,
Cesar