本文介绍了清除TEdit控件rad studio delphi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用右侧的TEdit控件时,留小图标 x。

When use TEdit control on the right side stay small icon 'x'. How after click on icon clear TEdit box.

全部保留!

推荐答案

Delphi提供了 TClearEditButton 来清除 TEdit 内容。可以通过右键单击并从弹出菜单中选择 AddItem-TClearEditButton 来添加。它还在FMX.Edit单元中覆盖了Click过程,例如:

Delphi provide TClearEditButton to clear the TEdit content. It can be added by right clicking and selecting AddItem - TClearEditButton from the popup menu. It also has a Click procedure overriden in FMX.Edit unit like:

procedure TClearEditButton.Click;
var
  EditTmp: TCustomEdit;
begin
  inherited Click;
  EditTmp := GetEdit;
  if EditTmp <> nil then
  begin
    if EditTmp.Observers.IsObserving(TObserverMapping.EditLinkID) then
      if not TLinkObservers.EditLinkEdit(EditTmp.Observers) then
        Exit; // Can't change
    EditTmp.Text := string.Empty;
    if EditTmp.Observers.IsObserving(TObserverMapping.EditLinkID) then
      TLinkObservers.EditLinkModified(EditTmp.Observers);
    if EditTmp.Observers.IsObserving(TObserverMapping.ControlValueID) then
      TLinkObservers.ControlValueModified(EditTmp.Observers);
  end;
end;

这使您无需编写 OnClick TClearEditButton 的事件处理程序,除非您想在清除编辑内容的同时做其他工作。

Which make you don't need to write OnClick event handler for the TClearEditButton unless you want to do some other job along side with clearing the edit.

如果您使用的是 TEditButton ,则应编写 OnClick 事件处理程序,例如:

If you are using a TEditButton then you should write the OnClick event handler like:

procedure TForm1.EditButton1Click(Sender: TObject);
begin
  Edit1.Text:= EmptyStr;
end;

这篇关于清除TEdit控件rad studio delphi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 16:40