1
votes

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

Tnx all!

enter image description here

1
VCL or FireMonkey?Ilyes
@Sami FireMonkeyuser_odoo
@Sami I'm create new blank mobile and device app and add TEdit control. Afrer click on 'X' nothing happens. I'm beginner.user_odoo
I create a new blank project with TEdit and TClearEditButton, the button works just fine. (Delphi 10 Seattle)Ilyes
@Sami That is TEdit button!user_odoo

1 Answers

4
votes

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;