Writing an Event Handler for the Button
Go Up to Getting started with IntraWeb Index
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.
- 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;
void fastcall TformMain::Button1Click(TObject *Sender)
{
}
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;
void __fastcall TformMain::IWButton1Click(TObject *Sender) { UnicodeString s; s = editName->Text; if (s.Length() == 0) { WebApplication->ShowMessage("Please Enter Your Name"); } else { WebApplication->ShowMessage("Hello, " + s + "!"); editName->Text = ""; } }
For information about running the completed application, see Running the Completed Application.