Recent

Author Topic: [SOLVED] Converting a string/index to upper/lower ...  (Read 5323 times)

1HuntnMan

  • Full Member
  • ***
  • Posts: 200
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
[SOLVED] Converting a string/index to upper/lower ...
« on: April 10, 2024, 07:07:48 pm »
Is there an Upper conversion for a string.  Tried searching the Lazarus/FPC Help and can't find anything.
I've created a search box for the user to key in a search string, i.e. by the active index. I've done that but the issue is the index, i.e. STATUS.  If the table, let's say Proposals, has a field where the user can define the Proposal Status as HOT or ACTIVE, CLOSED, CANCELLED.  If a person using the system is looking for a particular Proposal and the active index is BYSTATUS which is index by the STATUS field ixCaseInsensitive. The STATUS field data in the STATUS table contains data in all upper-case. But in the search by index component of my form which is a JvDBSearchEdit component, testing you have to enter in all caps or the search won't work.  I am trying to convert the search to ignore case.   
I was attempting to convert the data in the table field to UpStatus:= Upper(searchstring).  Anyone have an idea?  Probably a simple solution.
« Last Edit: May 07, 2024, 10:26:19 pm by 1HuntnMan »

TRon

  • Hero Member
  • *****
  • Posts: 2784
Re: Converting a string/index to upper/lower ...
« Reply #1 on: April 10, 2024, 07:20:44 pm »
...
Tried searching the Lazarus/FPC Help and can't find anything.
...
I was attempting to convert the data in the table field to UpStatus:= Upper(searchstring).  Anyone have an idea?  Probably a simple solution.
Upcase and ToUpper.

Thaddy

  • Hero Member
  • *****
  • Posts: 14804
  • Censorship about opinions does not belong here.
Re: Converting a string/index to upper/lower ...
« Reply #2 on: April 10, 2024, 07:21:21 pm »
What is your encoding in the database, because string.ToUpper from sysutils should work. (or simply upcase from system). Maybe a, ahum, UTF8 version in Lazarus somewhere.
If that does not work, the component is at fault.
bitrate is always calculated like this:sample rate * bitdepth * number of channels.


TRon

  • Hero Member
  • *****
  • Posts: 2784
Re: Converting a string/index to upper/lower ...
« Reply #4 on: April 10, 2024, 07:24:32 pm »
And for good measures UpperCase.

'Nough to choose from me thinks. Must be at least one that fits the need ?

dseligo

  • Hero Member
  • *****
  • Posts: 1260
Re: Converting a string/index to upper/lower ...
« Reply #5 on: April 10, 2024, 07:27:53 pm »
What is your encoding in the database, because string.ToUpper from sysutils should work. (or simply upcase from system). Maybe a, ahum, UTF8 version in Lazarus somewhere.
If that does not work, the component is at fault.

ToUpper doesn't work for UTF8. AnsiUpperCase and AnsiLowerCase should be used (https://wiki.freepascal.org/Unicode_Support_in_Lazarus#Coming_from_older_Lazarus_.2B_LCL_versions).

Thaddy

  • Hero Member
  • *****
  • Posts: 14804
  • Censorship about opinions does not belong here.
Re: Converting a string/index to upper/lower ...
« Reply #6 on: April 10, 2024, 07:37:53 pm »
Not with the WideString and UnicodeString variants in trunk.
Again proof about the really poor UTF8 implementation in Lazarus.
But I suspect, as I wrote, the UTF8 support units have something like that.
bitrate is always calculated like this:sample rate * bitdepth * number of channels.

dsiders

  • Hero Member
  • *****
  • Posts: 1147
Re: Converting a string/index to upper/lower ...
« Reply #7 on: April 10, 2024, 07:54:56 pm »
Again proof about the really poor UTF8 implementation in Lazarus.

Have you files any bug reports with specifics. General statements like that are hard to address.

But I suspect, as I wrote, the UTF8 support units have something like that.

https://lazarus-ccr.sourceforge.io/docs/lazutils/lazutf8/utf8uppercase.html
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Thaddy

  • Hero Member
  • *****
  • Posts: 14804
  • Censorship about opinions does not belong here.
Re: Converting a string/index to upper/lower ...
« Reply #8 on: April 10, 2024, 08:48:53 pm »
All I mean is that UTF8 is the default in Lazarus and that it is not a native FPC string type. Hence you will need to jump through hoops and take some quirky conversions from decent string types for granted.

Note I am not against that, I merely want to say UTF8 is NOT native so it can become a trouble, as it often does.

I seem to remember there was quite a discussion over supporting UTF8 on the compiler level and it did not materialize. Nowadays, with UNICODE16 string support in the compiler and the assignment compatibility that is less of an issue, but every now and then the lion puts up its roar....
It is really frustrating to have to use UTF8whatever conversion calls.... Your code looks sick, Ill. Dying.
And the conversion unit isn't even part of FPC, which is even more frustrating. It should belong in the RTL.
« Last Edit: April 10, 2024, 09:02:46 pm by Thaddy »
bitrate is always calculated like this:sample rate * bitdepth * number of channels.

1HuntnMan

  • Full Member
  • ***
  • Posts: 200
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Converting a string/index to upper/lower ...
« Reply #9 on: April 10, 2024, 11:05:18 pm »
TRon/All,
   See the attached code you shared with me awhile back when I was first learning about JvDBSearchEdit.  This works great except if the index selected is on let's say Client Name or Contact Name or the Sales/Joborder STATUS.  These fields are indexed CaseInsensitive but the friend who's a fellow photographer is testing, he sets the index by Client, or Contact or Status but he has to type his search string in the exact case as he entered the data in the tables. Attached is the the 2 procedures you shared with me for a Combo Box to select the index and the JvDBSearchEdit to search by the index selected by the user.

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TFrmSalesJOrders.CmboBxSelectIndexSelect(Sender: TObject);
  3. begin
  4.   Case CmboBxSelectIndex.Text of
  5.     'Client Name':DbfJobOrders.IndexName:= 'CUSTOMER';
  6.     'Contact':DbfJoborders.IndexName:= 'CONTACT';
  7.     'Status':DbfJobOrders.IndexName:= 'STATUS';
  8.     'Job/Sales Order Date':DbfJobOrders.IndexName:= 'ORDERDATE';
  9.     'Job/Sales Order No.':DbfJobOrders.IndexName:= 'JOBORDERNO';
  10.   else
  11.     WriteLn ('Index Unchanged!');
  12.   end;
  13.   JvDBSrchEditJO.DataField:= '';
  14.   DbfJobOrders.Refresh;
  15. end;
  16.  
  17. procedure TFrmSalesJOrders.CmboBxSelectIndexExit(Sender: TObject);
  18. var
  19.   I:Integer;
  20. begin
  21.   keys:= TStringList.Create;
  22.   keys.Delimiter:= ':';
  23.   keys.NameValueSeparator:= '=';
  24.   keys.StrictDelimiter:= True;
  25.   keys.DelimitedText:= 'Client Name=CLIENT:Contact=CNTKLNAME:'+
  26.    'Status=STATUS:Job/Sales Order Date=ORDERDATE:'+
  27.    'Job/Sales Order No.=Str(ORDERNO)';
  28.   I := keys.IndexOfName(CmboBxSelectIndex.Text);
  29.   if I <> -1 then JvDBSrchEditJO.DataField:= keys.ValueFromIndex[I];
  30.   DbfContacts.Refresh;
  31. end;
  32.  
  33.  

TRon

  • Hero Member
  • *****
  • Posts: 2784
Re: Converting a string/index to upper/lower ...
« Reply #10 on: April 11, 2024, 12:22:59 am »
@1HuntnMan:
I am not sure if I understood you correctly so apologies in case this reply makes no sense.

So far I understood that the jvDBsearchedit is entered in another case than required by your program.

You can extract the contents of the edit by using the text property and upcase that before actually applying but the edit itself also seem to have a loCaseInsensitive in its property SearchOptions which you perhaps could (ab)use.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Converting a string/index to upper/lower ...
« Reply #11 on: April 11, 2024, 12:50:53 am »
Code: Pascal  [Select][+][-]
  1. procedure TFrmSalesJOrders.CmboBxSelectIndexSelect(Sender: TObject);
  2. begin
  3.   Case CmboBxSelectIndex.Text of
A case statement work with ordinal values, not text? Maybe I missed something ...
Code: Pascal  [Select][+][-]
  1. procedure TFrmSalesJOrders.CmboBxSelectIndexExit(Sender: TObject);
  2. begin
  3.   keys:= TStringList.Create;
Are you aware about that you create a memory leak everytime you call that method?

My suggestion to fix your issues
 - work with ordinal values in case statement (like index of the combobox, I assume that you know all the time what index represent what "logic")
 - rethink about creation of instances and what happen to memory when you create something

It would be good if you add a minimalistic demo that shows your error.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

dseligo

  • Hero Member
  • *****
  • Posts: 1260
Re: Converting a string/index to upper/lower ...
« Reply #12 on: April 11, 2024, 01:00:56 am »
Code: Pascal  [Select][+][-]
  1. procedure TFrmSalesJOrders.CmboBxSelectIndexSelect(Sender: TObject);
  2. begin
  3.   Case CmboBxSelectIndex.Text of
A case statement work with ordinal values, not text? Maybe I missed something ...

You did. Read the last part: https://www.freepascal.org/docs-html/ref/refsu56.html

1HuntnMan

  • Full Member
  • ***
  • Posts: 200
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Converting a string/index to upper/lower ...
« Reply #13 on: April 11, 2024, 05:32:22 pm »
There are no errors with any of these two procedures.  Just the user typing into the JvDBSearchEdit lower case when the values in let's say the STATUS table which he entered into the table everything in upper case.  Nothing is going to be found if the index selected is by STATUS table, field contents are all upper-case. Or in the case of searching for a particular Client/Company where he entered the company names in first-letter upper-case and the rest is lower case. He has to enter in the JvDBSearchEdit first-letter upper case and the rest lower case.  I need to convert the search to search by all upper-case if the data in the table is all upper-case or convert the table contents for Company before the search to COMPANY, etc. for the search to work no-matter what case is being typed!
Just from the replies, I think I can do some experimenting with UpCase and ToUpper, thanks!

wp

  • Hero Member
  • *****
  • Posts: 12069
Re: Converting a string/index to upper/lower ...
« Reply #14 on: April 11, 2024, 06:23:06 pm »
I'm not sure whether I understand the issue. But did you notice that TJvDBSearchEdit has in its SearchOptions property an element loCaseInsensitive for case-independent search?

 

TinyPortal © 2005-2018