Solved

Ignoring case in Delphi field

Posted on 2010-09-20
13
1,296 Views
Last Modified: 2012-05-10
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.Filter do begin
      Clear;
      Root.BoolOperatorKind := fboAND;
     
      if cbContractor.Text <> '' then    AddItem(Root,gvResultsContractor, foLike, sContractor , sContractor);
      if edStreet_Name.Text <> '' then   AddItem(Root,gvResultsStreet_Name, foLike, sStreetName , sStreetName);
      if edBuyer.Text <> '' then         AddItem(Root,gvResultsBuyer, 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...
     
0
Comment
Question by:Bianca
  • 4
  • 2
  • 2
  • +3
13 Comments
 
LVL 1

Expert Comment

by:CesarHdez
ID: 33718209
Hi Prec94513, try applying upper(FIELDNAME) = 'SOMETHING', this will not affect how you display the data on your grid

Hope this works,

Cesar
0
 

Author Comment

by:Bianca
ID: 33718305
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.
0
 
LVL 1

Expert Comment

by:CesarHdez
ID: 33718843
Hi, for a start you need to convert your compare variables to uppercase

sContractor := '%' + UpperCase(cbContractor.Text) + '%';
sStreetName := '%' + UpperCase(edStreet_Name.Text) + '%';
sBuyer := '%' + UpperCase(edBuyer.Text) + '%';

with gvresults.DataController.Filter do begin
      Clear;
      Root.BoolOperatorKind := fboAND;

      (gvResultsX where do you build it?)

      if cbContractor.Text <> '' then    AddItem(Root,gvResultsContractor, foLike, sContractor , sContractor);
      if edStreet_Name.Text <> '' then   AddItem(Root,gvResultsStreet_Name, foLike, sStreetName , sStreetName);
      if edBuyer.Text <> '' then         AddItem(Root,gvResultsBuyer, foLike, sBuyer , sBuyer);

0
 
LVL 5

Accepted Solution

by:
briangochnauer earned 250 total points
ID: 33719756
             gvresults.DataController.Filter .Options := [fcoCaseInsensitive];
0
 
LVL 1

Expert Comment

by:CesarHdez
ID: 33719861
ah, that's even better! nice one
0
 
LVL 8

Expert Comment

by:GeneralTackett
ID: 33721424
easiest way is to uppercase() both sides or upper()  or use ansicompare with the ignore case option
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 9

Expert Comment

by:auke_t
ID: 33724391
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.Filter.Options := [fcoCaseInsensitive];

You can also set it in during design in the object inspector.
0
 
LVL 6

Expert Comment

by:saravananvg
ID: 33740657
Hi,
  As GeneralTackett says, you need to compare it on both sides as follows.

 UpperCase(sContractor) := '%' + UpperCase(cbContractor.Text) + '%';
 UpperCase(sStreetName) := '%' + UpperCase(edStreet_Name.Text) + '%';
 UpperCase(sBuyer) := '%' + UpperCase(edBuyer.Text) + '%';

with regards
Padmaja.
0
 
LVL 6

Expert Comment

by:saravananvg
ID: 33740667
Hi
  Sorry, need to compare it on both sides with if statement.

with regards,
Padmaja.
   
0
 
LVL 1

Expert Comment

by:CesarHdez
ID: 33745222
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...
0
 
LVL 8

Expert Comment

by:GeneralTackett
ID: 33745899
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.Text) + '%')) and
( UpperCase(sStreetName) )=( '%' + UpperCase(edStreet_Name.Text) + '%')) and
( UpperCase(sBuyer))=( '%' + UpperCase(edBuyer.Text) + '%'))
then begin
.....
end
else begin
...
end;
0
 
LVL 9

Expert Comment

by:auke_t
ID: 33751447
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.
0
 
LVL 5

Expert Comment

by:briangochnauer
ID: 33753364
The author of this question has not been involved.??
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now