Recent

Author Topic: Enter Key in TEdit  (Read 19907 times)

raturney@houston.rr.com

  • Guest
Enter Key in TEdit
« on: July 22, 2005, 07:12:33 am »
I am using a TEdit control to enter a decimal number, press "Enter", shift the focus to the next TEdit control to enter another number.  I have written code that works, but only if I press "Ctrl-Enter" instead of "Enter". I thought #13 was the code for carraige return/enter key.  If so, why does this only work using "Ctrl-Enter"?  Any ideas would be appreciated.
Thanks,
Bob

Code: [Select]

procedure TfrmPV.edtODKeyPress(Sender: TObject; var Key: char);

begin
   with Sender as TEdit do
   ShowMessage('Begin');
   case Key of
   '0'..'9' : ShowMessage('0-9 was pressed.');
   '.', ',' : ShowMessage('Period or Comma was pressed.');
   #8 :  ;
   #13 : begin
            ShowMessage('#13 was pressed.');
            Panel1.SelectNext(Sender as TWinControl, True, True);
            Key := #0;
         end;
   #10 : begin
            Panel1.SelectNext(Sender as TWinControl, True, True);
            Key := #0;
         end;
   else
         Key := #0;
   end;
end;

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2673
Enter Key in TEdit
« Reply #1 on: July 22, 2005, 02:13:14 pm »
Try als keydown and keyup events. I'm not sure if #10 and/or #13 are pased to keypress
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Anonymous

  • Guest
Enter Key in TEdit
« Reply #2 on: July 22, 2005, 03:49:08 pm »
Thank you very much, that worked!
-Bob

Code: [Select]
procedure TfrmPV.edtODKeyPress(Sender: TObject; var Key: char);
begin
   case Key of
   '0'..'9' : ShowMessage('0-9 was pressed.');
   '.', ',' : ShowMessage('Period or Comma was pressed.');
   else
      Key := #0;
   end;
end;

procedure TfrmPV.edtODKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
   if Chr(Key) = #13 Then
     begin
        ShowMessage('#13 was pressed.');
        Panel1.SelectNext(Sender as TWinControl, True, True);
     end;
end;

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2673
Enter Key in TEdit
« Reply #3 on: July 25, 2005, 03:58:04 pm »
In KeyDown and Keyup events, better check with the VirtualKeycodes like VK_RETURN, VK_TAB etc. then using Chr(Key). (a virtual kay can be larger than 255)
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Anonymous

  • Guest
Enter Key in TEdit
« Reply #4 on: July 27, 2005, 03:02:09 pm »
I have noticed that using the code listed above, that the Key values for entries from the "Keypad" (the keys on the far right side of the keyboard) are not processed.  Although the numbers entered from the top row are processed.  I noticed this after setting up a way to count the number of "periods/decimal points" entered.  The "period was detected when entered from the standard part of the keyboard, but was not seen when entered from the "keypad" on the far right side of the keyboard and was allowed to pass through the event handler.  Any ideas on this?

I have been looking for information to see if the  key codes for the "Keypad" are different from the ones returned from the top row.  Maybe the "VK_" codes are the answer.  I don't know where to find a listing of them.  Would Delphi documentation have the list of these codes?

Thanks,
-Bob

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2673
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Anonymous

  • Guest
Enter Key in TEdit
« Reply #6 on: August 05, 2005, 02:57:58 pm »
Thanks for link (and help).  I'll have a look.
-Bob

 

TinyPortal © 2005-2018