Board index » delphi » TEdit Bell

TEdit Bell

If I try to enter a "forbidden" character (i.e. asci < 32) into a TEdit, a
bell (I think it must be the Windows "Critical Stop") sounds.  Does anyone
know how to prevent this?

thanks,

James

 

Re:TEdit Bell


Quote
>>If I try to enter a "forbidden" character (i.e. asci < 32) into a TEdit, a
>>bell (I think it must be the Windows "Critical Stop") sounds.  Does anyone
>>know how to prevent this?

The basic idea is to set the unwanted keystroke character to #0:

procedure TWaveMgrForm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key < #32 then
    Key := #0;
end;

=Bill=

Re:TEdit Bell


Bill,

Actually, I want the "forbidden" character and I can actually get it, but I
can't get rid of the bell. Any other ideas?

James

Re:TEdit Bell


Quote
>>Actually, I want the "forbidden" character and I can actually get it, but I
>>can't get rid of the bell.

The only way that I know of to get rid of the bell is to handle the keypress event
and then set the char to #0.

You can't handle the "forbidden" character in onKeypress?

=Bill=

Re:TEdit Bell


Bill:

Actually, I am creating the "forbidden" character in the OnKeyPress event.

I need to display some of the characters from the OEM character set,
specifically #31 and #26.   So in my OnKeyPress I have:

case UpCase(Key) of

...
  'A' : Key := #26;
  'W' Key := #31;
...
end;

I have managed to convince a stringgrid to draw these characters so my app
works fine except I get the bell when I hit 'A' or 'W'.

Any suggestions?

thanks,

James

Re:TEdit Bell


Bill:

In case you're still reading this thread, I worked out something that does
the job.   In my OnKeyPress I am using translations to "acceptable"
characters, and then I am converting those characters to the "fobidden" ones
that I actually need in the OnDrawCell of my StringGrid.  Ugly, but it
works.  Thanks.

James

Re:TEdit Bell


Quote
In article <73amk4$5...@forums.borland.com>, James A. Schulz wrote:
> I have managed to convince a stringgrid to draw these characters so my app
> works fine except I get the bell when I hit 'A' or 'W'.

> Any suggestions?

I think you will not get the bell if you directly insert the character into
the control instead of letting it do that itself. E.g. in OnKeyPress:

  If key < #32 then begin
    (Sender As TEdit).SelText := Key;
    Key := #0;
  end;

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitely requested!

Other Threads