Tedit components are primarily used for data input and display and editing operations.
AutoSelect
Gets the component focus. This property can only be used in a single-line text component. A value of True is selected. False is not selected.
BorderStyle
Sets the appearance effect of the edit box control. The value is Bssingle, which is a single-line border. No border for Bsnone
CanUndo
This property determines the Undo method fallback when the user modifies the text.
Charcase
Sets the case for the text of the edit box control.
MaxLength
Sets the maximum length of the text, which is 0, which indicates no limit on length.
PasswordChar
Used to display the word wildcard common (*) symbol to set the password
ReadOnly
Set read-only and cannot modify the text content of a component
SelStart
Sets the starting position of the text and, if 0, points to the first text.
SelLength
Set the maximum length of text
Example selects text of the specified length
procedure Tform1.button1click (sender:tobject); Begin Edit3.setfocus; // Get Focus // set the starting position of a character Edit3.sellength:=strtoint (Edit2.text); // sets the number of characters end;
Events for Tedit components
OnChange
This event is triggered when the edit box component is changed
Example verifies the legitimacy of text
procedure Tform1.edit1change (sender:tobject);varStr:string; begin STR:="'; STR:=Edit1.text; ifLength (str) >0 ThenifNot (Str[length (str)]inch['0'..'9',#8] THEN begin Application.messagebox ('Please enter a number (','Tips', mb_okcancel+mb_iconinformation);
Edit1.text:=leftstr (Str,length (STR)-1); End Edit1.selstart:=Length (edit1.text); end;
OnEnter
The event is generated when the component accepts input focus and enables event handling to perform the specified processing when the window component is active.
Settings for the sample component focus
procedure Tform1.edit1enter (sender:tobject); BeginifSender isTedit then (Sender asTedit). Color: =$00c8ffffElse ifSender isTcombobox then (Sender asTcombobox). Color: =$00c8ffff;end;procedure tform1.edit1exit (sender:tobject); BeginifSender isTedit then (Sender asTedit). Color: =ClwhiteElse ifSender isTcombobox then (Sender asTcombobox). Color: =Clwhite;end;
OnExit
Events that occur when the focus is left
OnKeyPress
This event occurs when a key on the keyboard is pressed
Example restricting the input data
Procedure Tform1.edit1keypress (Sender:tobject;varKey:char); BeginifNot (Keyinch['a'..'Z','A'..'Z',#8] THEN begin Application.messagebox ('You can only enter English characters! ','Tips', Mb_okcancel +mb_iconinformation); Key:= #0; End;end;
OnKeyDown
Press the key on the keyboard to trigger the event, the key of which is an integer, which is determined by the keyboard's virtual key value.
Example shows the key values that are pressed on the keyboard
Procedure Tform1.formkeydown (Sender:tobject;varKey:word; shift:tshiftstate); Begin Edit2.text:=IntToStr (Key); ifShift =[Ssshift] then Edit1.text:='Shift' Else ifShift =[Ssalt] then Edit1.text:='Alt' Else ifShift =[Ssctrl] then Edit1.text:='Ctrl' ElseEdit1.text:="'; end;
Delphi edit box control (Tedit)