Clear TEdit control rad studio delphi

烈酒焚心 提交于 2019-12-02 10:40:08

问题


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

Tnx all!


回答1:


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;

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.

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;


来源:https://stackoverflow.com/questions/52466752/clear-tedit-control-rad-studio-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!