Sign in Join
Wiki copytemporary

TEdit: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11A **TEdit** ![](/wiki-images/d/db/Tedit.png) is a control with a single line of editable text. It is available from the [[Standard tab]] of the [[Component Palette]].
22
33## Usage
44
55You can add a TEdit text input field to your [[TForm|form]] by clicking on it in the Standard tab of the component palette and place it on your form with one click. You can now edit this single-line text field at run time.
66
77If you want to use this text elsewhere, you can use it like every other [[String]].
88
99For example, if you have a TEdit *Edit1* on your form, you can use `myString := Edit1.Text;`. To change the shown text in *Edit1*, you can use `Edit1.Text := myString;`.
1010
1111If you want to display another text instead of the default text (e.g. *Edit1*) in a TEdit *Edit1* at the start of your application, you can proceed as follows:
1212
1313- Select the TEdit on your form with one click.
1414- Go to the properties tab in the Object Inspector.
1515- Select the property **Text** and change it in the neighbouring input field.
1616- In the same way, you can select the property **Name** and give the TEdit a better name.
1717
1818### Password input
1919
2020You can also easily use a TEdit to enter passwords. Then instead of the actually entered [[Char]] a PasswordChar is displayed.
2121
2222Little Example:
2323
2424- Create a new GUI application with a TEdit *Edit1* and a TButton *Button1* on the form.
2525- In the Object Inspector set the property PasswordChar of *Edit1* to am asterisk ( * ).
2626- In the event handler of *OnClick* of *Button1* show the entered password: `ShowMessage(Edit1.Text);`.
2727
2828### TextHint
2929
3030Have you used a GUI that has, for example, a Search Box where you can type in a search term. And when unused, that Search Box displays something like "Search Here" so you know what it is for ? Well, TEdit has a property called TextHint for that purpose. Set TextHint to some appropriate text and if the normal 'Text' is empty and the Control is not in use, your Search Here message is displayed. On most Widget Sets, the TextHint is automatically cleared once the user starts typing in there. The exception is GTK2/3, they like to clear things as soon as the Control gets focus.
3131
3232The text from TextHint is displays a little greyer than normal text so the user is aware it is somehow special. Most people find this interface quite intuitive.
3333
3434## Requested Features
3535
3636### Embedding Button/Other Controls in TEdit
3737
3838It's a WinAPI feature to allow embedding any sort of control into a TEdit.
3939
4040Considerations.
4141
4242- The feature is not supported by all Widgetsets natively. For example: for Gtk2/Gtk3 it's not possible, as GtkEntry is not derived from a container. The SpinEdit control is a special kind of control in Gtk2. (This is the main reason on why [[TSpinEdit]] has its own WS class).
4343
4444- The placement of an embedded control (or controls) cannot be set by Left or Top properties (as normally happens). Instead the "Align" property should be used.
4545
4646```delphi
4747button1.Parent:=edit1;
4848button1.Width:=20;
4949button1.Align:=alRight;
5050button1.Constraints.MaxHeight:=18; //edit1.Height;
5151```
5252
5353- The "text" entry field must be limited by some TEdit property
5454
5555
5656OR this should be done automatically by the widgetset.
5757
5858Without such a limitation, the entered text goes "underneath" the embedded button.
5959
60-<figure>
61-<img src="edit1.gif" title="edit1.gif" />
62-<figcaption>edit1.gif</figcaption>
63-</figure>
60+![](/wiki-images/8/87/Edit1.gif)
6461
6562If using pure WinAPI, this can be achieved by using an EM_SETMARGINS message:
6663
6764```delphi
6865Uses
6966 Windows, ...
7067
7168...
7269
7370 SendMessage(Edit1.Handle, EM_SETMARGINS, EC_LEFTMARGIN or EC_RIGHTMARGIN, MakeLParam(0, button1.Width))
7471```
7572
76-<figure>
77-<img src="edit2.gif" title="edit2.gif" />
78-<figcaption>edit2.gif</figcaption>
79-</figure>
73+![](/wiki-images/5/53/Edit2.gif)
8074
8175The Delphi VCL does provide a Margins property, but it is not mapped to EM_SETMARGINS and has a different meaning in the VCL.
8276
8377## See also
8478
8579- [[doc:lcl/stdctrls/tedit.html|TEdit doc]]
8680- [[TMemo]] - A multiline text edit box
8781- [[TLabeledEdit]] - An edit field like a TEdit with a label
8882- [[TMaskEdit]] - An edit field with an edit mask
8983- [[TSpinEdit]] - An edit field for integers defined numbers range limits
9084- [[TFloatSpinEdit]] - An edit field for tiles floating-point numbers with defined numbers range limits
9185- [[TEditButton]] - An edit field like a TEdit with an attached button as a [[TSpeedBtn]]
9286- [[TFileNameEdit]] - An edit field with attached [[TOpenDialog]], to enter a file name
9387- [[TDirectoryEdit]] - An edit field with attached [[TSelectDirectoryDialog]], to enter a file path
9488- [[TDateEdit]] - An edit field with attached [[TCalendarDialog]] (calendar), to enter a date
9589- [[TCalcEdit]] - An input field with attached [[TCalculatorDialog]] (Calculator), to enter a number
9690- [[TTIEdit]] - An RTTI capable input field
9791
9892---
9993*From the Free Pascal wiki, page "TEdit", as it stood on 2022-12-06 after a change by Dbannon, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history