Using WINAPI, I can specify ES_NUMBER to an edit control to specify that the edit control can only accept numbers. I don't seem to find any way to do that in TEdit. Perhaps there should be a property called AllowedChar, which is an enum of (acAll, acAlpha, acNumber, acHex, acBin, ac...). I would like to help, but the problem is, how do I prevent the control from painting the pressed key? I've created a workaround, but it looks bad. It's something like:
procedure TMainForm.EditCtrlKeyPress(Sender: TObject; var Key: char);
var
buf: String;
begin
if not(Key in ['0'..'9'] then begin
buf:=EditCtrl.Text;
buf:=Copy(buf,1,length(buf)-1);
EditCtrl.Text:=buf;
end;
end;
First, it can't handle words pasted from clipboard. Second, the key will be painted first before it's deleted (I STILL CAN SEE IT BEFORE IT'S DELETED!). I need to catch the message before it's handled by the edit control. But I just don't know how.