Code

Code

So far we have built only a static page. To add interactivity we can use data binding or code. In this section we will add some code.

Control Names

To facilitate easy access to our controls from code, we need to give them names.  This can easily be done using the object inspector, but it is faster to simply modify the IWML:

Not every control requires a name. Only the controls that we want to interact with in code must be given names. This is why we did not give names to the SimpleStack or Gap.

Adding Code

With Delphi code can be added server side (Delphi) or client side (JavaScript) in an integrated manner. We will start by adding very simple code and then will return and modify it later into useful application logic.

Server Code

Select the button in the tree. Open the Object Inspector.

Select Events and double click the OnClicked event:

Only One Event???

Note that there is only one event available? This is because the screenshot was taken from a beta version. More events will exist on button in the release version of IntraWeb 17.

Add the Code

After you double click the event value, a server side event will be created for you:

In the new event add this code:

procedure TUnit1.GuessButtonClick(aSender: T17Renderer);
begin
  Guess.Text := 'Hello World!';
end;

Since server code does not run in preview, we have to run the application and then launch a browser. After launching and clicking the button it will look like this:

Just as in earlier versions of IntraWeb, you can fully debug your code using watches, breakpoints and more.