Recent

Author Topic: (Solved) StringGrid character Case  (Read 2696 times)

iru

  • Sr. Member
  • ****
  • Posts: 321
(Solved) StringGrid character Case
« on: April 04, 2021, 05:17:52 am »
Gentlefolk,

My environment/s :Win10, Laz 2.0.10, FPC 3.2.0, Linux Mint 20.1 2.0.12, FPC 3.2.0.

My problem:
In both environments I have a simple form with a StringGrid. I have a single event handler 'OnKeyDown' on the StringGrid.

In both environments any alpha keyboard input is presented in UPPER CASE.

I have used a crash and the 'View/DebugWidows/CallStack to chase the entry of the lower case 'a'.
The input is a uppercase 'A' all the way: As shown in the following:

Any ideas why no lower case in StringGrid????? Ian

#0 fpc_raiseexception at :0
#1 GETCELLS(0x15a2d50, 1, 999) at grids.pas:9942
#2 SETCELLS(0x15fdee0, 1, 999, 0x15a48e8 'A') at grids.pas:10996
#3 STRINGGRID1KEYDOWN(0x15fc500, 0x15fdee0, 65, []) at unit1.pas:46
#4 KEYDOWN(0x15fdee0, 65, []) at include\wincontrol.inc:5674
#5 KEYDOWN(0x15fdee0, 65, []) at grids.pas:7389
#6 KEYDOWN(0x15fdee0, 65, []) at grids.pas:10663
#7 KEYDOWNBEFOREINTERFACE(0x15fdee0, 65, []) at include\wincontrol.inc:5684.......
#8 DOKEYDOWNBEFOREINTERFACE(0x15fdee0, {MSG = 48384, UNUSEDMSG = 0, CHARCODE = 65......

Surely 
« Last Edit: April 05, 2021, 12:15:32 am by iru »

dseligo

  • Hero Member
  • *****
  • Posts: 1478
Re: StringGrid character Case
« Reply #1 on: April 04, 2021, 11:08:43 am »
I am not sure what 'alpha keyboard' is, but try to use OnKeyPress event. You'll get lower and upper case.

wp

  • Hero Member
  • *****
  • Posts: 12678
Re: StringGrid character Case
« Reply #2 on: April 04, 2021, 11:57:30 am »
CAPS LOCK pressed?

MarkMLl

  • Hero Member
  • *****
  • Posts: 8317
Re: StringGrid character Case
« Reply #3 on: April 04, 2021, 01:08:14 pm »
Note what the other guys say, but check whether you're able to type lowercase into a shell... if not something's broken at the system level (e.g. one of your Little Darlings has dropped a paperclip into your keyboard :-)

Noting that you're running multiple disparate systems: beware of the mix of e.g. VNC and multiple desktops, since it's possible for injudicious switching to get a stuck capslock state on the remote server even if the local client hasn't got it pressed.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

iru

  • Sr. Member
  • ****
  • Posts: 321
Re: StringGrid character Case
« Reply #4 on: April 04, 2021, 02:32:58 pm »
Gentlefolk,

Thanks for the responses.

If I place a TEdit on the same form I can input upper and lower case!
Both computers are lenovo X240.
As a sanity check I borrowed my son's old HP running win10. Installed Laz-FPC and created the same form.

Same problem, upper and lower case in the tEdit, UPPER case in the StringGrid..

Ian

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: StringGrid character Case
« Reply #5 on: April 04, 2021, 03:17:29 pm »
Gentlefolk,


My problem:
In both environments I have a simple form with a StringGrid. I have a single event handler 'OnKeyDown' on the StringGrid.
 

There is no published OnKeyDown event for a StringGrid.
Show us some code please.

Winni

dseligo

  • Hero Member
  • *****
  • Posts: 1478
Re: StringGrid character Case
« Reply #6 on: April 04, 2021, 04:03:19 pm »
There is no published OnKeyDown event for a StringGrid.
Yes, there is, at least in 2.0.10.
Check the attachment.

dseligo

  • Hero Member
  • *****
  • Posts: 1478
Re: StringGrid character Case
« Reply #7 on: April 04, 2021, 04:09:21 pm »
If I place a TEdit on the same form I can input upper and lower case!
Both computers are lenovo X240.
As a sanity check I borrowed my son's old HP running win10. Installed Laz-FPC and created the same form.

Same problem, upper and lower case in the tEdit, UPPER case in the StringGrid..
I assume you don't use OnKeyDown event in TEdit, you just look what is in the box where you type?

If you use OnKeyDown event of TEdit, you will get same result. I can't promise I can explain very precise, but simplified, the reason that OnKeyDown doesn't give you upper and lower case is that OnKeyDown gives you the actual keys you pressed (disregarding state of Caps lock, Num lock).

You didn't answer why you can't use OnKeyPress event?

sstvmaster

  • Sr. Member
  • ****
  • Posts: 302
Re: StringGrid character Case
« Reply #8 on: April 04, 2021, 05:16:42 pm »
OnKeyDown means: "Is a Key pressed?" For read the text/char you must use OnKeyPress!

Quote
Handler for keyboard key pressed.

This handler can filter keys, for special use in e.g. non-textual controls.

The handler receives all keystrokes, including control and other non-visual keys. Keys are encoded as virtual
 keys, with separate active modifier keys.

Text input instead should be checked in an OnKeyPress handler.
greetings Maik

Windows 10,
- Lazarus 3.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 4.99 (trunk) + fpc 3.3.1 (main/trunk)

sstvmaster

  • Sr. Member
  • ****
  • Posts: 302
Re: StringGrid character Case
« Reply #9 on: April 04, 2021, 05:20:24 pm »
...
There is no published OnKeyDown event for a StringGrid.
...
Yes there is Winni in 2.0.12 and trunk.
greetings Maik

Windows 10,
- Lazarus 3.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 4.99 (trunk) + fpc 3.3.1 (main/trunk)

wp

  • Hero Member
  • *****
  • Posts: 12678
Re: StringGrid character Case
« Reply #10 on: April 04, 2021, 05:22:54 pm »
In both environments I have a simple form with a StringGrid. I have a single event handler 'OnKeyDown' on the StringGrid.

In both environments any alpha keyboard input is presented in UPPER CASE.

Your description is very vague.

Do you mean that every alphanumeric character typed into a grid cell is shown in uppercase? To my knowledge this can only happen when you have CAPS LOCKed as I suspected earlier, or something is very wrong.

Or do you mean that the character assigned to the Key parameter of the OnKeydown event is upper-case? The latter is normal because the "Key" is only the code to identify the physical key on the keyboard. You must also consider the Shift argument to determine whether the "A" key pressed is an upper-case or a lower-case A. An even this is not correct, because there are many more key codes. Simply use the OnKeyPress event to determine character assigned to the pressed key (including Shift states).

sstvmaster

  • Sr. Member
  • ****
  • Posts: 302
Re: StringGrid character Case
« Reply #11 on: April 04, 2021, 05:38:06 pm »
I think he means this. see attachment.
greetings Maik

Windows 10,
- Lazarus 3.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 4.99 (trunk) + fpc 3.3.1 (main/trunk)

jamie

  • Hero Member
  • *****
  • Posts: 6819
Re: StringGrid character Case
« Reply #12 on: April 04, 2021, 06:48:42 pm »
If you are reading the key code given in the Onkeydown event then that is normal..

There is only one value for the letter 'A' and that is 0x41 and this is called virtual key codes.

These codes represent the keyboard and if you look you will see there is only one letter 'A' on the keyboard.

if you need to look at the case status then you need to use the shift information coming in with the event.

using the onKeyPress will give you the expected value you are looking for..


other than that, I don't know what issue you have because it works fine here.
The only true wisdom is knowing you know nothing

MarkMLl

  • Hero Member
  • *****
  • Posts: 8317
Re: StringGrid character Case
« Reply #13 on: April 04, 2021, 08:53:44 pm »
If you are reading the key code given in the Onkeydown event then that is normal..

There is only one value for the letter 'A' and that is 0x41 and this is called virtual key codes.

These codes represent the keyboard and if you look you will see there is only one letter 'A' on the keyboard.

if you need to look at the case status then you need to use the shift information coming in with the event.

Well spotted Jamie.

Code: Pascal  [Select][+][-]
  1. type TKeyEvent = procedure(
  2.  
  3.   Sender: TObject;
  4.  
  5.   var Key: Word;
  6.  
  7.   Shift: TShiftState
  8.  
  9. ) of object;
  10.  

The important point there being that the key is returned as a word, not as a char, so shouldn't automatically be assumed to be one.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: StringGrid character Case
« Reply #14 on: April 04, 2021, 10:08:53 pm »


The important point there being that the key is returned as a word, not as a char, so shouldn't automatically be assumed to be one.

MarkMLl


Hi!
To make it clear:

The value of key can be something  like

VK_ESCAPE
VK_RETURN
VK_F1
VK_BACK

Look at the constants in LCLtype.

Winni

 

TinyPortal © 2005-2018