1
votes

Does anyone of you know how to clear back all the data that I have insert in TEdit field in a form after I click submit button?

I have a button "save" and after I click on this button, some message will appear like " the data have been saved". At the same time, I want the TEdit field clear from all the data that I have insert before this.

The show message appear but the TEdit field remain the same.

I don't know how to make this happen.

1
Do you know software which acts like this? Clearing all input fields and then telling you it has been saved? (I don't.) Why not just leave everything filled? And what keeps you from setting TEdit.Text to an empty String?AmigoJack
You don't need to waste your time doing things like this. Learn about data-aware controls like TDBEdit.MartynA
TCustomEdit has a public Clear() method.: "Deletes all text from the edit control."Remy Lebeau

1 Answers

1
votes

The following code snippet will reset the Text value of all TEdit objects (and other descendants of TCustomEdit, such as TLabeledEdit, TMaskEdit or TMemo) found on the form. Thus, after pressing the "Save" button, the entire screen will be cleared.

Additionally you can use DB objects for this. Thus, the relevant fields will be reset automatically after the Append/Post operation. Another recommendation is that if the screen will close after the "Save" button, the free agent of the relevant form will reset all objects again. You will need to create that form while opening it, and you need to send it to the "Available forms" side from Project -> Options -> Forms so that it does not auto-create.

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
begin
 for I := 0 to Self.ComponentCount - 1 do
 begin
   if Self.Components[I] is TCustomEdit then
   begin
     (Self.Components[I] as TCustomEdit).Text := '';
   end;
 end;
end;