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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help... how to use CaseInsensitive with setkey

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hi,
i'm using setkey to search for a particular surname and names from a table...

DataM.TMast.IndexName:='Names';

DataM.TMast.SetKey;
DataM.TMast['p_surname']:=Sname1.Text;
DataM.TMast['o_names']:=Name1.Text;
DataM.TMast.GotoNearest;

my problem is that eventhough a record exists, it does not go to the nearest match because field 'o_names' contains names in lower and upper case. Is it possible to do this...


DataM.TMast.IndexName:='Names';
DataM.TMast.SetKey;
DataM.TMast['p_surname']:=Sname1.Text;
Uppercase(DataM.TMast['o_names']):=Uppercase(Name1.Text);
DataM.TMast.GotoNearest;

or is there another way rather than locate with locaseInsensitive.
 
I think this code could help you in your problem...


Function StrToUpper(str1 : string) : string;
var
ctr : integer;
ResultStr : string;
begin
ResultStr := '';
for ctr := 1 to length(str1) do
begin
ResultStr := ResultStr + Upcase(str1[ctr]);
end;
Result := ResultStr;
end;

just bear in mind that the UPCASE function does not convert a string... only a character at a time therefore you have to loop from surname[1] to surname[nth]...


 
Hello, HitokiriBattousai. And what's happend to such a nice functions like UpperCase/LowerCase and AnsiUpperCase/AnsiLowerCase that conver the whole string? :)

--- markus
 
hi,

I've tried to uppercase the field like that...

Uppercase(DataM.TMast['o_names']):=Uppercase(Name1.Text);

but i get this message...
left side cannot be assigned to

 
From what i can see you are using TTable. So i can suggest you to add a calculated field, say O_NAMES_UP. Then add OnCalcFields handler to your Table, it can look like this:
Code:
procedure TForm1.Table1CalcFields(DataSet: TDataSet);
begin
  DataSet.FieldByName('O_NAMES_UP').asString := UpperCase(DataSet.FieldByName('O_NAMES').asString);
end;
Once you've done it use this field when performing a search.
Hope that helps.

--- markus
 
You want your original code to be this:

DataM.TMast['o_names']:=Uppercase(Name1.Text);

Your error is that you are doing a function to both sides of your equation.
Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Leslie that won't work because you are casting to upper case only condition and the field value is left intact. "SetKey" is a sort of "Locate" method so your solution won't work.

--- markus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top