RAD Studio
ContentsIndex
PreviousUpNext
Writing an Event Handler for the Button

The form does not yet perform any actions when the user clicks the OK button.  

For information on editing the main form, see Editing the Main Form.

You will now write an event handler that will display a greeting when the user clicks OK.

  1. Double-click the OK button on the form. An empty event handler is created in the editor window, like the one shown here:

procedure TformMain.IWButton1Click(Sender: TObject);
begin

end;

  1. Using the editor, add code to the event handler so it looks like the following:

procedure TformMain.IWButton1Click(Sender: TObject);
var s: string;
begin
   s := editName.Text;
   if Length(s) = 0 then
      WebApplication.ShowMessage("Please enter your name.")
   else
   begin
      WebApplication.ShowMessage("Hello, " + s +"!");
      editName.Text := "";
   end;
end;

For information about running the completed application, see Running the Completed Application.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!