Difference between revisions of "TEdit"
m (→Embedding Button/Other Controls in TEdit: grammar) |
(→Requested Features: Update syntax highlighting; fix typos) |
||
Line 25: | Line 25: | ||
==Requested Features== | ==Requested Features== | ||
+ | |||
===Embedding Button/Other Controls in TEdit=== | ===Embedding Button/Other Controls in TEdit=== | ||
− | It's a WinAPI feature to allow embedding any | + | |
+ | It's a WinAPI feature to allow embedding any sort of control into a TEdit. | ||
Considerations. | Considerations. | ||
− | * 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. SpinEdit control is a special kind of control in Gtk2. (This the main reason on why [[TSpinEdit]] has | + | * 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). |
− | * The placement of an embedded control (or controls) cannot be set by Left or Top properties (as | + | * 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. |
− | < | + | |
− | + | <syntaxhighlight lang="delphi"> | |
− | + | button1.Parent:=edit1; | |
− | + | button1.Width:=20; | |
− | + | button1.Align:=alRight; | |
− | </ | + | button1.Constraints.MaxHeight:=18; //edit1.Height; |
+ | </syntaxhighlight> | ||
* The "text" entry field must be limited by some TEdit property | * The "text" entry field must be limited by some TEdit property | ||
:OR this should be done automatically by the widgetset. | :OR this should be done automatically by the widgetset. | ||
− | + | Without such a limitation, the entered text goes "underneath" the embedded button. | |
[[Image:edit1.gif]] | [[Image:edit1.gif]] | ||
− | If using pure WinAPI, this can be achieved by using EM_SETMARGINS message: | + | If using pure WinAPI, this can be achieved by using an EM_SETMARGINS message: |
− | < | + | |
− | + | <syntaxhighlight lang="delphi"> | |
+ | Uses | ||
Windows, ... | Windows, ... | ||
... | ... | ||
+ | |||
SendMessage(Edit1.Handle, EM_SETMARGINS, EC_LEFTMARGIN or EC_RIGHTMARGIN, MakeLParam(0, button1.Width)) | SendMessage(Edit1.Handle, EM_SETMARGINS, EC_LEFTMARGIN or EC_RIGHTMARGIN, MakeLParam(0, button1.Width)) | ||
− | </ | + | </syntaxhighlight> |
[[Image:edit2.gif]] | [[Image:edit2.gif]] | ||
− | Delphi VCL does provide Margins property, but | + | 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== | ==See also== |
Revision as of 05:22, 27 March 2021
│
Deutsch (de) │
English (en) │
suomi (fi) │
français (fr) │
日本語 (ja) │
русский (ru) │
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 to your form a TEdit input box add by clicking on it at the Standard component palette and place it on your form with one click. You can now edit this single-line text box at run time.
Want you this text elsewhere have, you can read this text, like every other String.
For example, you have a TEdit Edit1 on your form placed, 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:
- Select the TEdit on your form with one click.
- Go to the properties tab in the Object Inspector.
- Select the property Text and change it in the next input box.
- In the same way, you can select the property Name and give the TEdit a better name.
Password input
You can also easily use a TEdit to enter passwords. It is then instead of actually entered Char a PasswordChar displayed.
Little Example:
- Create a new GUI application with a TEdit Edit1 and a TButton Button1 on the form.
- In the Object Inspector set the property PasswordChar of Edit1 to a " * ".
- In the event handler of OnClick of Button1 show the entered password:
ShowMessage(Edit1.Text);
Requested Features
Embedding Button/Other Controls in TEdit
It's a WinAPI feature to allow embedding any sort of control into a TEdit.
Considerations.
- 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).
- 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.
button1.Parent:=edit1;
button1.Width:=20;
button1.Align:=alRight;
button1.Constraints.MaxHeight:=18; //edit1.Height;
- The "text" entry field must be limited by some TEdit property
- 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:
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
- TEdit doc
- TMemo - A multiline text edit box
- TLabeledEdit - An edit field like a TEdit with a label
- TMaskEdit - An edit field with an edit mask
- TSpinEdit - An edit field for integers defined numbers range limits
- TFloatSpinEdit - An edit field for tiles floating-point numbers with defined numbers range limits
- TEditButton - An edit field like a TEdit with an attached button as a TSpeedBtn
- TFileNameEdit - An edit field with attached TOpenDialog, to enter a file name
- TDirectoryEdit - An edit field with attached TSelectDirectoryDialog, to enter a file path
- TDateEdit - An edit field with attached TCalendarDialog (calendar), to enter a date
- TCalcEdit - An input field with attached TCalculatorDialog (Calculator), to enter a number
- TTIEdit - An RTTI capable input field