Recent

Author Topic: TEdit key press events in customdrawn LCLWidgetType  (Read 342 times)

lagprogramming

  • Full Member
  • ***
  • Posts: 217
TEdit key press events in customdrawn LCLWidgetType
« on: February 08, 2023, 04:38:38 pm »
Using Linux, add a standard TEdit on a Form and fill the OnKeyPress with the following code:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: char);
  2. begin
  3.   if key=chr(13) then form1.Caption:=form1.Caption+'>';
  4. end;

The above event is triggered when the project is running Linux using default gtk2 LCLWidgetType.
Now go to "Project/Project options..." menu, "Additions and Overrides", set the LCLWidgetType value to "customdrawn". Run the project again and you might see that the key press event is not triggered at all. I've looked at OnUTF8KeyPress event and this one is triggered for both gtk2 and customdrawn. Gtk2 triggers OnUTF8KeyPress before OnKeyPress, customdrawn triggers OnUTF8KeyPress and doesn't trigger OnKeyPress at all.

Maybe it's a bug.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: TEdit key press events in customdrawn LCLWidgetType
« Reply #1 on: February 08, 2023, 04:54:50 pm »
Hi!

Never call inside a TForm1 procedure Form1!!!!
That might be dangerous.

Do it that way:

Code: Pascal  [Select][+][-]
  1. if key=#13 then self.Caption:=self.Caption+'>';

or even shorter:

Code: Pascal  [Select][+][-]
  1. if key=#13 then Caption:=Caption+'>';

Winni

lagprogramming

  • Full Member
  • ***
  • Posts: 217
Re: TEdit key press events in customdrawn LCLWidgetType
« Reply #2 on: February 09, 2023, 02:55:40 pm »
@winni For sure that's not the main problem here.
In the meantime I've done an additional test. You don't need a TEdit, TForm class has the same problem. The OnKeyPress event of a form is never triggerd, only the OnUTF8KeyPress.

 

TinyPortal © 2005-2018