TEdit/ja
│
Deutsch (de) │
English (en) │
suomi (fi) │
français (fr) │
日本語 (ja) │
русский (ru) │
TEdit は1行編集のコントロールである。コンポーネントパレットのStandardタブにある。
使い方
TEditはコンポーネントパレットのStandardタブにあるTEditアイコンをクリックし、フォームform上で1回クリックすることで加えることができる。これで、実行時にこの1行テキストフィールドを編集できる。
もし、このテキストを別の場所で使いたいときは、他のStringのように用いることができる。
例えば、もしTEdit Edit1をフォームに加えると、myString := Edit1.Text;
を持ちることができる。
もし、アプリケーションの起動時TEdit Edit1の中のデフォルトテキスト(例えば、Edit1)をほかのものを表示するようにしたいなら、以下のように進めることができる:
- フォーム上のTEditをクリックによって選択する。
- オブジェクトインスペクタのプロパティタブに移動する。
- プロパティTextを選択し、隣の入力フィールドを変更する。
- 同様にして、プロパティNameを選択し、TEditをましな名前にする。
パスワード入力
TEditを簡単にパスワードを入力に用いることができる。このようにして、実際に入力したCharに代わり、パスワード文字を表示させる。
簡単な例:
- 新しいTEdit TEdit Edit1を持つGUIアプリケーションを作り、TButton Button1をフォームに置く。
- オブジェクトインスペクタでEdit1のパスワード文字プロパティを、1つのアスタリスク( * )にする。
- Button1のOnClickイベントハンドラは入力されたパスワードを:
ShowMessage(Edit1.Text);
と示す。
テキストヒント
例えば、検索語を入力できる検索ボックスに入力したことはあるだろうか。そして使われてないときは、検索語ボックスはそれが何のためにあるか知らせるために「検索」のようなものを表示しているのを見たことはあるだろうか。そう、TEditはこの目的のためにTextHintと呼ばれるプロパティを持っている。TextHintは通常の「Text」が空でコントロールが使用されていない場合は、「検索」メッセージが表示される。たいていの部品ではTextHintはユーザーがタイプを始めると自動的にそこから消える。この例外はGTK2/3で、コントロールがフォーカスを得ると直ちに、中身を消し去る。
TextHintからのテキストは通常のテキストより、幾分灰色がかっており、そのためユーザーは何か特別なものと気づく。大方の人はこのインタフェースを直感的に理解する。
要望事項
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.
以下も参照のこと
- 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