Like the latter, TIWApplication is not a visual component. It does not appear on the object inspector and therefore does not have published properties. However, it has a number of public properties and methods that can be accessed via code in the IntraWeb application. Each user session has one TIWApplication instance.
|Country:||Trinidad & Tobago|
|Published (Last):||26 September 2010|
|PDF File Size:||6.11 Mb|
|ePub File Size:||12.12 Mb|
|Price:||Free* [*Free Regsitration Required]|
When you build an IntraWeb application, a number of components are available. For example, if you look at the IW Standard page of Delphi's Component Palette, you'll see an impressive list of core components, from the obvious button, check box, radio button, edit box, list box, memo, and so on to the intriguing tree view, menu, timer, grid, and link components.
I won't list each component and describe its use with an example—I'd rather use some of the components in a few demos and underline the architecture of IntraWeb rather than specific details. I've built an example called IWTree showcasing the menu and tree view components of IntraWeb but also featuring the creation of a component at run time.
This handy component makes available in a dynamic menu the content of a standard Delphi menu, by referring its AttachedMenu property to a TMenu component:. If the menu items handle the OnClick event in the code, they become links at run time. You can see an example of a menu in a browser in Figure The example's second component is a tree view with a set of predefined nodes.
Thanks to the similarity of IntraWeb components to standard Delphi VCL components, the code is easy to read and understand. The menu has two submenus, which are slightly more complex. The second submenu, Tree Contents, shows a list of the first tree nodes of the main level along with the number of direct subnodes. What's interesting, though, is that the information is displayed in a memo component created at run time see again Figure For example, this program's menu with alTop alignment, the tree view has alClient alignment, and the dynamic memo is created with alBottom alignment.
As an alternative, you can use anchors again working as in the VCL : You can create bottom-right buttons, or components in the middle of the page, with all four anchors set. See the following demos for examples of this technique.
All the programs you have built so far have had a single page. Now let's create an IntraWeb application with a second page. As you'll see, even in this case, IntraWeb development resembles standard Delphi or Kylix development, and is different than most other Internet development libraries.
This example will also serve as an excuse to delve into some of the source code automatically generated by the IntraWeb application wizard. Let's start from the beginning. This powerful component allows you to place within an HTML grid both text and other components.
In the example, the grid content is determined at startup in the OnCreate event handler of the main form :. The effect of this code is shown in Figure In addition to the output, there are a few interesting things to notice. First, the grid component uses Delphi anchors all set to False to generate code that keeps it centered in the page, even if a user resizes the browser window.
Add to this page a few IntraWeb components, as usual, and then add to the main form a button or other control you'll use to show the secondary form with the reference anotherform stored in a field of the main form :. Even if the program calls the Show method, it can be considered like a ShowModal call, because IntraWeb considers visible pages as a stack.
The last page displayed is on the top of the stack and is displayed in the browser. By closing this page hiding or destroying it , you re-display the previous page. In the program, the secondary pages closes itself by calling the Release method, which as in the VCL is the proper way to dispose of a currently executing form.
You can also hide the secondary form and then display it again, to avoid re-creating it each time particularly if doing so implies losing the user's editing operations. In the program I added a Close button to the main form. It should not call Release , but rather should invoke the WebApplication object's Terminate method, passing the output message, as in WebApplication. Terminate 'Goodbye! The demo uses an alternative call: TerminateAndRedirect. Now that you have seen how to create an IntraWeb application with two forms, let's briefly examine how IntraWeb creates the main form.
The relevant code, generated by the IntraWeb wizard as you create a new program, is in the project file:. This is different from Delphi's standard project file, because it calls a global function instead of applying a method to a global object representing the application.
The effect, though, is quite similar. The two parameters are the classes of the main form and of the IntraWeb controller, which handle sessions and other features as you'll see in a while. The secondary form of the IWTwoForms example shows another interesting feature of IntraWeb: its extensive graphics support.
The form has a graphical component with the classic Delphi Athena image. This is accomplished by loading a bitmap into the an IWImage component: IntraWeb converts the bitmap into a JPEG, stores it in a cache folder created under the application folder, and returns a reference to it, with the following HTML:. The extra feature provided by IntraWeb and exploited by the program is that a user can click on the image with the mouse to modify the image by launching server-side code.
In this program, the effect is to draw small green circles. The painting operation takes place on the bitmap canvas. If you've done any web programming, you know that session management is a complex issue.
IntraWeb provides predefined session management and simplifies the way you work with sessions. If you need session data for a specific form, all you have to do is add a field to that form. The IntraWeb forms and their components have an instance for each user session.
As a contrast, I've also declared a global unit variable called GlobalCount , which is shared by all the instances or sessions of the application. To increase your control over session data and let multiple forms share it, you can customize the TUserSession class that the IntraWeb Application Wizard places in the ServerController unit. In the IWSession example, I've customized the class as follows:. In an application's code, the session object can be referenced by accessing the Data field of the RWebApplication global variable, used to access the current user's session.
It gives you access to the session data in a thread-safe way: you need to take special care to access it even in a multi-threading environment. This variable can be used outside of a form or control which are natively session-based , which is why it is primarily used inside data modules, global routines, and non-IntraWeb classes. Because most of this code is generated for you, after adding data to the TUserSession class you simply use it through the UserSession function, as in the following code extracted from the IWSession example.
When you click a button, the program increases several counters one global and two session-specific and shows their values in labels:. Notice that the program uses Windows' InterlockedIncrement call to avoid concurrent access to the global shared variable by multiple threads.
Figure The program has also a check box that activates a timer. Odd as it sounds, in an IntraWeb application, timers work almost the same as in Windows.
With this single line of code plus the addition of an IWModuleController component in the web module , the WebBroker application can embed an IntraWeb page, as the CgiIntra program does.
A component of this type must exist in every project for IntraWeb to work properly. This issue has been fixed and is a free update. Because this is a Page mode CGI application, it has no session management. Moreover, the status of the components in a page is not automatically updated by writing event handlers, as in a standard IntraWeb program. To accomplish the same effect you need to write specific code to handle further parameters of the HTTP request.
It should be clear even from this simple example that Page mode does less for you than Application mode, but it's more flexible. That topic isn't really related, because HTML layouts work also in Application mode—but I've happened to use these two techniques in a single example. In the programs built so far, the resulting page is the mapping of a series of components placed at design time on a form, in which you can use properties to modify the resulting HTML.
But what if you want to embed a data-entry form within a complex HTML page? The alternative approach is represented by the use of IntraWeb's layout managers. As you can see in Figure The HTML editor will be improved in a coming upgrade, and a few quirks will be fixed. The components are marked only with a special tag based on curly braces, as in the following of the example:. Thus the form becomes only a component holder, because the size and position of the form's components are ignored.
Toggle navigation. See also. Home Programming Mastering Delphi 7. Here is the code for a couple of event handlers: procedure TformTree. Count - 1 do IWTreeView1. Items [i]. Count - 1 do Lines.
Building IntraWeb Applications
Introduction In this tutorial you'll learn how to use multiple forms, how to handle user input and how to use sessions. In order to understand and run the example in this tutorial you should read the "Hello World" tutorial first. What is Next This application is built using IntraWeb's application mode. The last tutorial was very basic and designed to simply show you how easy it is to get an IntraWeb application up and running. As you will soon see the code used is still standard Delphi code.