// Make edit accept only numbers. // Method 1: Procedure tform1.edit1keypress (Sender: tobject; var key: Char); begin if not (key in ['0 '.. '9']) then key: = CHR (0); end; // Method 2: Procedure tform1.edit1keypress (Sender: tobject; var key: Char ); begin if not (byte (key) in [48 .. 57]) the ASCII value of then // 0 is 48 key: = CHR (0); end; // method 3: Procedure tform1.edit1keypress (Sender: tobject; var key: Char ); begin if not charinset (Key, ['1 '.. '5']) then key: = #0; end;
// Select the edit text and the cursor position procedure tform1.button1click (Sender: tobject); begin edit1.setfocus; // give the focus sendmessage (edit1.handle, em_setsel, 0, 1 ); // select the first character sendmessage (edit1.handle, em_setsel, 0,-1); // select sendmessage (edit1.handle, em_setsel ); // move the cursor to sendmessage (edit1.handle, em_setsel,) after the first character; // move the cursor to start sendmessage (edit1.handle, em_setsel,-); // move the cursor to start end;
// To be continued...