Search code examples
delphidelphi-xe6

Keypress firing buttonclick when not supposed to


This code worked OK under Delphi XE4. Under XE6 any char I enter in cxTextedit fires the button.

procedure TForm1.cxTextEdit1KeyPress(Sender: TObject; var Key: Char);
begin
if Key=chr(13) then
Key := #0;
AdvGlowButton1Click(Self);
end;

What could be wrong ?


Solution

  • The code you showed clicks the button on every character typed, in ALL Delphi versions. If you are trying to click the button only when ENTER is typed, then you are missing a required begin/end pair:

    procedure TForm1.cxTextEdit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if Key = #13 then
      begin // <-- add this
        Key := #0;
        AdvGlowButton1Click(Self);
      end; // <-- add this
    end;