Recent

Author Topic: TEdit && TStringGrid Keypress Event  (Read 10039 times)

GAlex

  • New Member
  • *
  • Posts: 13
TEdit && TStringGrid Keypress Event
« on: May 06, 2005, 06:48:16 pm »
i've used Lazarus 0.9.6+Freepascal 1.9.8 to develop a small app used to edit csv files for the VegaStrike project (an OpenSource SpaceSimEngine).

it works fine in win32...

BUT when i build this on linux (i use a SuSE 9.2 waiting the 9.3) with the same version of Lazarus+Freepascal, i got problems in the KeyPressEvent.

a keypress of <enter> in either one of the TEdit or the TStringGrid components at runtime does not spawn the relative function.

the two portions of the code are the following:
Code: [Select]
procedure TForm1.EditKeyPress(Sender: TObject; var Key: char);
begin
    if (Key = chr(10)) or (Key = chr(13)) then begin
        csv.Cells[csv.Col, csv.Row] := edit.text;
        csv.setfocus;
    end;
end;

for the TEdit named Edit and
Code: [Select]
procedure TForm1.csvKeyPress(Sender: TObject; var Key: char);
begin
    if (Key = chr(10)) or (Key = chr(13)) then begin
        edit.text := csv.Cells[csv.Col, csv.Row];
        edit.setfocus;
    end;
end;

for the TStringGrid named csv.

again: in win32 it DOES work.

why not in Linux???

need help.

jesusr

  • Sr. Member
  • ****
  • Posts: 499
Re: TEdit && TStringGrid Keypress Event
« Reply #1 on: May 07, 2005, 03:27:31 am »
Quote from: "GAlex"
i've used Lazarus 0.9.6+Freepascal 1.9.8 to develop a small app used to edit csv files for the VegaStrike project (an OpenSource SpaceSimEngine).

it works fine in win32...

BUT when i build this on linux (i use a SuSE 9.2 waiting the 9.3) with the same version of Lazarus+Freepascal, i got problems in the KeyPressEvent.

a keypress of <enter> in either one of the TEdit or the TStringGrid components at runtime does not spawn the relative function.

the two portions of the code are the following:
Code: [Select]
procedure TForm1.EditKeyPress(Sender: TObject; var Key: char);
begin
    if (Key = chr(10)) or (Key = chr(13)) then begin
        csv.Cells[csv.Col, csv.Row] := edit.text;
        csv.setfocus;
    end;
end;

for the TEdit named Edit and
Code: [Select]
procedure TForm1.csvKeyPress(Sender: TObject; var Key: char);
begin
    if (Key = chr(10)) or (Key = chr(13)) then begin
        edit.text := csv.Cells[csv.Col, csv.Row];
        edit.setfocus;
    end;
end;

for the TStringGrid named csv.

again: in win32 it DOES work.

why not in Linux???

need help.


The return key is handled by the editor in KEYDOWN, as result the Key is set to 0, this seems to prevent doing a posterior KEYPRESS for key #13 under linux but not in windows where KEYDOWN->KEYPRESS->KEYUP methods are called always.

Can you please submit a bugreport? so this will serve as a reminder.

Anonymous

  • Guest
TEdit && TStringGrid Keypress Event
« Reply #2 on: May 07, 2005, 04:06:44 pm »
bug posted. will wait for fix. thanks.

jesusr

  • Sr. Member
  • ****
  • Posts: 499
TEdit && TStringGrid Keypress Event
« Reply #3 on: May 09, 2005, 07:49:29 am »
Quote from: "Anonymous"
bug posted. will wait for fix. thanks.

Why don't you use KeyDown instead?

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2663
TEdit && TStringGrid Keypress Event
« Reply #4 on: May 11, 2005, 11:54:43 am »
Besides that, I don't think you will get a #10 (or Chr(10)) in a keypress event
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

GAlex

  • New Member
  • *
  • Posts: 13
TEdit && TStringGrid Keypress Event
« Reply #5 on: May 16, 2005, 02:56:18 pm »
Quote from: "Marc"
Besides that, I don't think you will get a #10 (or Chr(10)) in a keypress event
i know... but it is only for compatibility issues with (very) old keyboards like mine that generates a #13 on <enter> and a #10 on <keypadenter> (lots of problems having it works correctly).

in fact i'm now using keydown event in my linux build, but it's not so stylistically correct, and again i've developed my app originally in win32, then opened it in linux and... well you know... if one release an application wich should be multi-os and multi-platform it should also compile and run the same way...

thanks again.

 

TinyPortal © 2005-2018