Recent

Author Topic: How to force Uppercase in DBGrid text field entry  (Read 381 times)

erictan

  • Jr. Member
  • **
  • Posts: 52
How to force Uppercase in DBGrid text field entry
« on: July 08, 2020, 04:35:00 pm »
1) I have a DBGrid for data-entry, how can I force certain text field in the DBGrid to Uppercase.

2) What is the format to set the EditMask of the DBGrid for Text and Numeric fields.

I am not able to find any information in the internet.
Greatly appreciate any help on these issues.

GetMem

  • Hero Member
  • *****
  • Posts: 3752
Re: How to force Uppercase in DBGrid text field entry
« Reply #1 on: July 08, 2020, 06:38:28 pm »
I' m on my phone now, so I cannot test. IIRC there is an OnGetText event(double click the SQLQuery, select the field, go to Object Inspector, create the OnGetText event):
Code: Pascal  [Select][+][-]
  1. procedure TForm1.SQLQueryGetText(Sender: TField; var aText: string;  DisplayText: Boolean);
  2. begin
  3.   aText := UpperCase(Sender.AsString)
  4. end;  

Or something similar. :)
« Last Edit: July 08, 2020, 06:48:50 pm by GetMem »

erictan

  • Jr. Member
  • **
  • Posts: 52
Re: How to force Uppercase in DBGrid text field entry
« Reply #2 on: July 09, 2020, 12:50:18 am »
Thanks again GetMem, just tried your code and could not get the uppercase.

I did some googling and found another solution by putting '>cccccccccc' in the field EditMask but I did not quite like it, still prefer your sample code if it works.

GetMem

  • Hero Member
  • *****
  • Posts: 3752
Re: How to force Uppercase in DBGrid text field entry
« Reply #3 on: July 09, 2020, 06:56:04 am »
@erictan
Quote
Thanks again GetMem, just tried your code and could not get the uppercase.
You are welcome. I just ran a few test and it works fine at my side. See screenshot for more details.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.qBanksNameGetText(Sender: TField; var aText: string;
  2.   DisplayText: Boolean);
  3. begin
  4.   DisplayText := True;
  5.   aText := UpperCase(Sender.AsString);
  6. end;
  7.  
If still not works, please try to debug it, put a breakpoint to aText := ..., and see the values.


Quote
I did some googling and found another solution by putting '>cccccccccc' in the field EditMask but I did not quite like it, still prefer your sample code if it works.
According to the documentation '>cccccccccc' is a valid solution: https://wiki.freepascal.org/TMaskEdit, however it does not work for some reason.

erictan

  • Jr. Member
  • **
  • Posts: 52
Re: How to force Uppercase in DBGrid text field entry
« Reply #4 on: July 09, 2020, 09:15:45 am »
I did get '>cccccccccc' to work for me but I don't like the underscore they used as character placement.

The sample is from this website. http://www.delphigroups.info/2/70/41095.html
This is part of the chat.....
Yes, that's because of the 'a's. Change it to 'c' to accept any character, or 'l' to accept only alfas. Uppercases to *require* input.

Examples:
'>aaaaa;0; ': accept up to 5 alfanumerics converted to uppercase
'>LLLLL;0; ': requires 5 alfas converted to uppercase
'<CCCCC;0; ': requires 5 chars converted to lowercase (<);
'>LL<CCCC<>ccccc;0; ': requires 2 alfas (converted to uppercase), followed by 4 required chars (converted to lowercase), then permits up to 5 chars (case as entered); etc...

The 0 (zero) after the first semicolon is for 'do not save literal chars' (there are none in the examples anyway) and notice the final space after the second semicolon, which is to avoid a marker as long as the picture (default underscore).
For all other possibilities (numerics only, signed numerics, required or permitted etc...), search for EditMask in the help-files.


 

TinyPortal © 2005-2018