PDA

View Full Version : Edit boxes and the return button



wisebede
22-02-2006, 12:30 PM
Its not quite game related, but I have a quick chat program where I have an edit box to enter text. When the return key is pressed, the text is processed and the contents of the text box cleared. However the TEdit box seems to have a peculiar feature that if the return key is pressed, the Windows error sound is given. Is there a way around this? Setting the value of key to 0 in the keydown event doesn’t seem to help. A TMemo might be a solution, but that seems to create an extra line of text after pressing return that I can’t get rid of.

Any help appreciated,

Matt.

Huehnerschaender
22-02-2006, 01:50 PM
In OnKeyPress-Event put this:

if Key = #13 then begin
SendMessage(GetParentForm(Self).Handle, WM_NEXTDLGCTL, 0, 0);

This lets the sound "disappear".

Greetings,
Dirk

jdarling
22-02-2006, 02:10 PM
You can also just set Key to #0 as follows:


procedure TForm1.EditKeyPress(Sender:TObject; var Key : Char);
begin
if Key = #13 then
begin
// Your processing here
Key := #0;
end;
end;

wisebede
22-02-2006, 02:22 PM
By jove, thats it. I was close, but no cigar. Thankyou very much indeed.