Previous Topic

Next Topic

Inhoudsopgave

Book Index

TEdit Control

TEdit

Description

Provides a single-line edit control.

Remarks

Use a TEdit object to put a standard Windows edit control on a form. Edit controls are used to retrieve text that users type. Edit controls can also display text to the user. When only displaying text to the user, choose an edit control to allow users to select text and copy it to the Clipboard. Choose the TLabel control if the selection capabilities of an edit control are not needed.

TEdit Properties

Property Property AutoSelect: Boolean (R/W)

Determines whether all the text in the edit control is automatically selected when the control gets focus. Set AutoSelect to select all the text when the edit control gets focus. AutoSelect only applies to single-line edit controls. Use AutoSelect when the user is more likely to replace the text in the edit control than to append to it.

Property Property AutoSize: Boolean (R/W)

Determines whether the height of the edit control automatically resizes to accommodate the text. Use AutoSize to make the edit control adjust its size automatically so the client area accommodates the height of the text. When AutoSize is false, the edit control has a fixed height. When AutoSize is true, the size of the control is readjusted whenever a change occurs that could affect the height of the control, such as a change to the font or border style.

Note: AutoSize only adjusts the height of the edit control. Even with AutoSize set to true, text in the edit control may appear truncated if it extends beyond the width of the control.

Property Property BorderStyle: Enumerated (bsNone, bsSingle)(R/W)

Determines whether the edit control has a single line border around the client area. Use BorderStyle to affect the sharpness with which the client area of the edit control stands out. BorderStyle can have a value of either bsSingle or bsNone. If BorderStyle is bsSingle, the edit control has a single-line border around the client area. If BorderStyle is bsNone, there will be no border.

Property Property CanUndo: Boolean (R)

Read CanUndo to determine whether the user has made any changes to the text that can be undone by calling the Undo method. This is useful when enabling or disabling menu items that correspond to these commands.

Property Property CharCase: Enumerated (ecNormal, ecUpperCase, ecLowerCase)(R/W)

Determines the case of the text within the edit control. Use CharCase to force the contents of the edit control to assume a particular case. When CharCase is set to ecLowerCase or ecUpperCase, the case of characters is converted as the user types them into the edit control. Changing the CharCase property to ecLowerCase or ecUpperCase changes the actual contents of the text, not just the appearance. Any case information is lost and can't be recaptured by changing CharCase to ecNormal.

Property Property HideSelection: Boolean (R/W)

Determines whether the visual indication of the selected text remains when focus shifts to another control. Set HideSelection to false to provide visual feedback of the selected portion of the text even when the edit control does not have focus. Set HideSelection to true to show the selection only when the edit control has focus. HideSelection does not affect the actual value of the selection, only the visual indication. Always setting HideSelection to false can make forms with many edit controls look too busy.

Property Property MaxLength: Integer (R/W)

Use MaxLength to limit the number of characters that can be entered into the edit control. A value of 0 indicates that there is no application-defined limit on the length.

Use MaxLength to limit the length of the text in an edit control if that text will be copied into a fixed-length buffer.

Note: Setting MaxLength will not truncate the existing text, it merely prevents the user from adding more text after reaching the limit of MaxLength characters. Even when MaxLength is 0, there may be limitations imposed by the operating system on the number of characters that may be entered into an edit control.

Property Property Modified: Boolean (R)

Indicates whether the user edited the text of the edit control. Use Modified to determine whether the Text property of the edit control changed. If an application directly alters the Text property of an edit control, it should set the Modified property to true.

Property Property PasswordChar: Char (R/W)

Indicates the character, if any, to display in place of the actual characters typed in the control. Use the PasswordChar property to create an edit control that displays a special character in place of any entered text. If PasswordChar is empty, the edit control displays its text normally. If PasswordChar is any other character, the edit control displays PasswordChar in place of each character typed. PasswordChar affects the appearance of the edit control only. The value of the Text property reflects the actual characters that are typed.

Property Property ReadOnly: Boolean (R/W)

Determines whether the user can change the text of the edit control. To restrict the edit control to display only, set the ReadOnly property to true. Set ReadOnly to false to allow the contents of the edit control to be edited. Setting ReadOnly to true ensures that the text is not altered, while still allowing the user to select text. The selected text can then be manipulated by the application, or copied to the Clipboard.

Property Property SelLength: Integer (R/W)

Specifies the number of characters (bytes) that are selected. Read SelLength to determine the length, in bytes, of the selected text. This is the same as the number of characters, unless you are using a multi-byte character set. Set SelLength to change the selection to consist of the first SelLength bytes starting at SelStart.

Note: Setting SelLength to a value greater than the number of characters from SelStart to the end of the text results in the selection of all characters from SelStart to the end of the text. Reading SelLength immediately after setting it to a value greater than the number of available characters returns the number of characters actually selected, not the value that was just set.

Property Property SelStart: Integer (R/W)

Specifies the position of the first selected character in the text. Read SelStart to determine the position of the first selected character, where 0 indicates the first character. If there is no selected text, SelStart indicates the position of the cursor. Set SelStart to remove the current selection and position the cursor just before the indicated character. To select a particular range of the text, first set SelStart to position the cursor, and then set SelLength to extend the selection.

Property Property SelText: String (R/W)

Specifies the selected portion of the edit control's text. Read SelText to determine the value of the selected text. Set SelText to replace the selected text with a new string. If there is no selection, but the edit control has focus, set SelText to insert a new string into the text at the cursor.

Property Property Text: String (R/W)

Contains a text string associated with the editcontrol. Use the Text property to read the Text of the control or specify a new string for the Text value. For edit controls and memos, the Text appears within the control.

TEdit Methods

Method Method Clear

Deletes all text from the edit control. Use Clear to replace the Text property with an empty string. Clear removes all text, not just the selected text. To remove just the selected text, use ClearSelection.

Method Method ClearSelection

Removes the selected text from the edit control. Use ClearSelection to delete the selected text from the edit control. If no text is selected, ClearSelection does nothing. If all of the text is selected, ClearSelection clears all text, like the Clear method.

Method Method CopyToClipboard

Copies the selected text in the edit control to the Clipboard in text format. Use CopyToClipboard to replace the contents of the Clipboard with the selected text. CopyToClipboard does not clear the Clipboard if no text is selected. If no text is selected, CopyToClipboard does nothing.

Method Method CutToClipboard

Copies the selected text to the Clipboard in text format and then deletes the selection.

Use CutToClipboard to replace the contents of the Clipboard with the selected text while clearing the selected text. If no text is selected, CutToClipboard does nothing.

Method Method PasteFromClipboard

Pastes the contents of the Clipboard into edit control, replacing the current selection. Use PasteFromClipboard to replace the selected text with the contents of the Clipboard, or, if no text is selected, to insert the contents of the Clipboard at the cursor. If the Clipboard is empty, or if it does not contain anything in text format, PasteFromClipboard does nothing.

Method Method SelectAll

Selects all text in the edit control. Use SelectAll to select all text in the edit control. To select only part of the text, use the SelStart and SelLength properties.

Method Method Undo

Backs out all changes in the undo buffer. Call Undo to cancel all changes made to the Text property since the last call to the ClearUndo method. If ClearUndo was never called, Undo rolls back all changes. To determine whether there are any changes in the undo buffer, check the CanUndo property.