Search code examples
delphidelphi-7

Edit and onEnter event


I have problem with several things:

  1. How to make edit1.text be blank when i hit enter (i think it should be on onEnter event but not so sure)
  2. Is there any way to assign strings from Edit1.text to array?

With all that said all i wanna do is:

Enter a name in edit, click enter, and then enter another name in same edit and previous name to be saved in some variable or array. Is this even possible?

I tried procedure TForm1.Edit3Enter(Sender: TObject); but when i click enter nothing happens.


Solution

  • The OnEnter event is triggered when the Edit control receives keyboard input, not when the user pressed the Enter key. You should be using the OnKeyPress event for that, eg:

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    var
      S: String;
    begin
      if Key = #13 then
      begin
        Key := #0;  
        S := Edit1.Text;
        Edit1.Clear;
        // do something with S...
      end;
    end;