Sign in Join
Wiki copytemporary

TEdit

Deutsch · English · Français · Suomi · Русский · 日本語

A TEdit is a control with a single line of editable text. It is available from the Standard tab of the Component Palette.

Usage

You can add a TEdit text input field to your 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.

If you want to use this text elsewhere, you can use it like every other String.

For 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;.

If 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:

Password input

You can also easily use a TEdit to enter passwords. Then instead of the actually entered Char a PasswordChar is displayed.

Little Example:

TextHint

Have 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.

The 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.

Requested Features

Embedding Button/Other Controls in TEdit

It's a WinAPI feature to allow embedding any sort of control into a TEdit.

Considerations.

delphi
button1.Parent:=edit1;
button1.Width:=20;
button1.Align:=alRight;
button1.Constraints.MaxHeight:=18; //edit1.Height;

OR this should be done automatically by the widgetset.

Without such a limitation, the entered text goes "underneath" the embedded button.

If using pure WinAPI, this can be achieved by using an EM_SETMARGINS message:

delphi
Uses
  Windows, ...

...

  SendMessage(Edit1.Handle, EM_SETMARGINS, EC_LEFTMARGIN or EC_RIGHTMARGIN, MakeLParam(0, button1.Width))

The Delphi VCL does provide a Margins property, but it is not mapped to EM_SETMARGINS and has a different meaning in the VCL.

See also


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.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.