Академический Документы
Профессиональный Документы
Культура Документы
WebSnap Application
Borland
Delphi 7
for Windows
Borland Software Corporation
100 Enterprise Way, Scotts Valley, CA 95066-3249
www.borland.com
COPYRIGHT 20012002 Borland Software Corporation. All rights reserved. All Borland brand and product names
are trademarks or registered trademarks of Borland Software Corporation in the United States and other countries.
All other marks are the property of their respective owners.
D7-WS-0802
Contents
Creating a WebSnap application
Creating a WebSnap application . . . . . . . .
Starting the WebSnap application wizard .
Saving the generated files and project . . .
Specifying the application title . . . . . . .
Creating a CountryTable page . . . . . . . . .
Adding a new Web page module. . . . . .
Saving the new Web page module . . . . .
Adding data components to the
CountryTable module . . . . . . . . . . . . .
Adding data-aware components . . . . . .
Specifying a key field . . . . . . . . . . . .
Adding an adapter component . . . . . . .
Creating a grid to display the data . . . . . . .
Adding a grid . . . . . . . . . . . . . . . . .
Adding editing commands to the grid . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2
2
2
3
3
3
4
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5
5
6
6
7
7
9
Index
iii
. . . 10
. . . 10
. . . 11
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
11
11
12
13
14
14
15
15
15
16
iv
1
Creating a WebSnap application
Chapter1
This tutorial explains how to create a WebSnap application called Country Tutorial.
The application displays a table of information about countries to users on the Web.
Users can add, delete, and edit the table information.
Follow the tutorial instructions from beginning to end. If you need a break, use the
File|Save All command at any time to save your project.
When you have completed the tutorial, your application will look similar to the one
shown in Figure 2.
Figure 2
Note
This tutorial requires the Enterprise edition of Delphi, which includes WebSnap
components. The tutorial assumes that you are familiar with Windows and have
read the introduction to Delphi programming and the IDE in the Quick Start.
5 Click OK.
Tutorial
1 Choose File|New|Other.
2 In the New Items dialog box, select the WebSnap tab, choose WebSnap Page
Module, and click OK.
3 In the dialog box, set the Producer Type to AdapterPageProducer.
4 In the Page Name field enter CountryTable. Notice that the Title also changes as
you type.
5 Leave the rest of the fields with their default values.
The dialog should appear as shown in Figure 3.
6 Click OK.
Figure 3
New WebSnap Page Module dialog box for the CountryTable page
The CountryTable module should now appear in the IDE. After saving the module,
you will add new components to the CountryTable module.
1 Choose File|Save.
2 In the File name field, enter CountryTableU.pas and click Save.
Tutorial
1 In the Object TreeView, expand the Session and DBDemos node, then select the
country.db node. This node is the Country Table component.
2 Right-click the country.db node and select Fields Editor.
3 Right-click on the CountryTable.Country editor window and choose Add All
Fields.
4 Select the Name field from the list of added fields.
5 In the Object Inspector, expand the ProviderFlags property.
6 Set the pfInKey property to True.
1 Choose the DataSetAdapter component from the WebSnap tab of the Component
palette. Add it to the CountryTable Web module.
2 Change the following properties in the Object Inspector:
Set the DataSet property to Country.
Set the Name property to Adapter.
When you are finished, the CountryTable Web page module should look similar
to what is shown in Figure 4.
Figure 4
Since the elements in the module are non-visual, it doesnt matter where they appear
in the module. What matters is that your module contains the same components as
shown in the figure.
Tutorial
Figure 5
The Preview tab shows you what the final, static HTML page looks like in a Web
browser. That page is generated from a dynamic HTML page that includes script. To
see a text representation showing the script commands, select the HTML Script tab at
the bottom of the editor window (see Figure 6).
Figure 6
Tutorial
The HTML Script tab shows a mixture of HTML and script. HTML and script are
differentiated in the editor by font color and attributes. By default, HTML tags
appear in boldfaced black text, HTML attribute names appear in black, and HTML
attribute values appear in blue. Script, which appears between the script brackets <%
%>, is colored green. You can change the default font colors and attributes for these
items in the Color tab of the Editor Properties dialog, which can be displayed by
right-clicking on the editor and selecting Properties.
There are two other HTML-related editor tabs. The HTML Result tab shows the raw
HTML contents of the preview. Note that the HTML Result, HTML Script, and
Preview views are all read-only. You can use the HTML-related editor tab,
CountryTable.html, for editing.
If you want to improve the look of this page, you can add HTML using either the
CountryTable.html tab or an external editor at any time. For more information on
how to edit the page template, see the Advanced HTML Designsection of the
Developers Guides WebSnap chapter.
Figure 7
1 Choose File|New|Other.
2 In the New Items dialog box, select the WebSnap tab and choose WebSnap Page
Module and click OK.
3 In the dialog box, set the Producer Type to AdapterPageProducer.
4 Set the Page Name field to CountryForm.
10
Tutorial
5 Uncheck the Published box, so this page does not appear in a list of available
pages on this site. The Edit form is accessed through the Edit button, and its
contents depend on which row of the country table is to be modified.
6 Leave the rest of the fields and selections set to their default values. Click OK.
1 Choose File|Save.
2 In the File name field enter CountryFormU.pas and click Save.
11
7 In the Object Inspector, set the Adapter property to CountryTable.Adapter. Set the
AdapterMode property to Edit.
8 To preview the Page, click the Preview tab at the bottom of the code editor. Your
preview should resemble the one shown in Figure 8.
Figure 8
Adding buttons
Add components to the AdapterPageProducer component to generate the submit
buttons in the HTML form. To add components:
1 In the Object TreeView, expand the AdapterPageProducer component and all its
branches.
2 Right-click AdapterForm1 and choose New Component.
3 Select AdapterCommandGroup then click OK. An AdapterCommandGroup1
entry appears in the Object TreeView.
4 In the Object Inspector, set the DisplayComponent property to
AdapterFieldGroup1.
5 Right-click AdapterCommandGroup1 entry and choose Add Commands.
6 Press the Ctrl key and multi-select the Cancel, Apply, and Refresh Row
commands. Click OK.
12
Tutorial
7 To preview the page, click the Preview tab at the bottom of the code editor
window. If the preview does not show the country form, click the Code tab and
then click the Preview tab again. Your preview should resemble the one shown in
Figure 9.
Figure 9
13
14
Tutorial
15
1 Run the application and browse to the CountryTable page using the Web
Application Debugger. For information on how to do this, see Running the
completed application on page 14.
2 Open another browser window and browse to the CountryTable page.
3 Click the DeleteRow button on the first row in the grid.
4 Without refreshing the second browser, click the DeleteRow button on the first
row in the grid.
An error message, Row not found in Country, is displayed above the grid.
To test for form errors:
1 Run the application, and browse to the CountryTable page using the Web
Application debugger.
2 Click on the EditRow Button. The CountryForm page is displayed.
3 Change the area field to 'abc', and click the Apply Button.
An error message (Invalid value for field Area) will be displayed above the first
field.
You have now completed the WebSnap tutorial. You might want to recheck the Stop
on Delphi Exceptions checkbox before continuing. Also, save the application by
choosing File|Save All so your completed application is available for future
reference.
16
Tutorial
Index
B
T
title, specifying application 3
data-aware components 5
dataset adapter component 6
DBDEMOS sample database 5
Index
vi
Tutorial