Recent

Author Topic: [Solved]Triggering handler when Tedit editing is done  (Read 3695 times)

JFistere

  • New Member
  • *
  • Posts: 25
[Solved]Triggering handler when Tedit editing is done
« on: April 29, 2016, 10:53:58 am »
I have a Tedit entry window on a form, and a Go button. When the User presses the Go button the text is properly processed. What I would like it to do is have it behave the same when the user makes a change to the Tedit element and presses Enter. The controls that would appear to do this require the user to click someplace else as well, which is not intuitive or user-friendly.

How can I make hitting Enter behave like clicking the Go button?
« Last Edit: April 30, 2016, 12:14:32 am by JFistere »

balazsszekely

  • Guest
Re: Triggering handler when Tedit editing is done
« Reply #1 on: April 29, 2016, 11:22:31 am »
Try this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   ShowMessage('ok');
  4. end;
  5.  
  6. procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: char);
  7. begin
  8.   if Key = #13 then
  9.   begin
  10.     Key := #0;
  11.     Button1Click(Button1);
  12.   end;
  13. end;

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Triggering handler when Tedit editing is done
« Reply #2 on: April 29, 2016, 12:15:02 pm »
Use the OnEditingDone event.
It is triggered when user presses Enter and when user leaves the control

Bart

RWC

  • Jr. Member
  • **
  • Posts: 92
Re: Triggering handler when Tedit editing is done
« Reply #3 on: April 29, 2016, 02:19:51 pm »
@JFistere - What event does your Go button trigger?
LAZARUS  : Lazarus-1.4.2-fpc-2.6.4-win32. OS   : Windows Vista 32bit Home Premium SP2.
CPU  : Intel Core2 Quad CPU Q6600 2.4GHz. RAM : 3GB. PCIE : NVIDIA GeForce GT610. Audo : NVIDIA HD Audio.

JFistere

  • New Member
  • *
  • Posts: 25
Re: Triggering handler when Tedit editing is done
« Reply #4 on: April 30, 2016, 12:05:15 am »
@ GetMem: Works great. Thanks!

JFistere

  • New Member
  • *
  • Posts: 25
Re: Triggering handler when Tedit editing is done
« Reply #5 on: April 30, 2016, 12:13:11 am »
@Bart: That's the problem. I wanti to trigger Button1.Click before the mouse leaves the control. GetMem's solution does the job.

@RWC: Button1.Click.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Triggering handler when Tedit editing is done
« Reply #6 on: April 30, 2016, 11:38:36 pm »
@Bart: That's the problem. I wanti to trigger Button1.Click before the mouse leaves the control. GetMem's solution does the job.

You misunderstood me.

Notice that OnEditingDone is called whenever the user presses Enter in a TCustomEdit.
Iy does exactly what you want: it is triggered when the user is done editing.
In OnEditingDone simply call Button1Click.
The event is also (but not ony: see above) triggered if the user leaves the control.

Bart

 

TinyPortal © 2005-2018