📄 cb200006ne_f.asp.htm
字号:
<p class=Code><span class=Code> } </span></p>
<p class=Code><span class=Code> <i> <span Class=CodeBlue>// Initialize the built-in random number generator. </span></i></span></p>
<p class=Code><span class=Code> Randomize();</span></p>
<p class=Code><span class=Code>}</span></p>
<p class=BodyText> </p>
<p class=BodyText> In the <i>OnCreate</i>
event handler of our Web module, we delete all image files stored on the Web
application directory for more than ten minutes, and initialize the random
value generator. </p>
<p class=BodyText> At last,
we can right-click the <i>TDataSetTableProducer</i>,
select the Response Editor option, and change the appearance of the HTML table (see Figure
19). </p>
<p class=BodyText> </p>
<p class=Captions> <img
width=250 height=296 src="images/cb200006ne_f_image034.gif" tppabs="http://www.cbuilderzine.com/features/2000/06/cb200006ne_f/cb200006ne_f_image034.gif"><br>
<b>Figure 19:</b>
The response editor. </p>
<p class=BodyText> </p>
<p class=BodyText> For
example, we can change the <i>Cellpadding</i>,
<i>Cellspacing</i>, <i>Border</i>, and <i>BgColor</i>
properties of the HTML table. These properties are responsible for the distance
between cells, thickness of the lines, and cell color. In addition, we can
generate <i>THTMLTableColumn</i> objects and
change their properties, allowing us to present columns and their headers in
different ways. </p>
<p class=BodyText> </p>
<p class=BodyText> Save,
compile, and test the project. The result is shown in Figure 20. </p>
<p class=BodyText> </p>
<p class=Captions> <img
width=250 height=296 src="images/cb200006ne_f_image036.gif" tppabs="http://www.cbuilderzine.com/features/2000/06/cb200006ne_f/cb200006ne_f_image036.gif"><br>
<b>Figure 20:</b>
Publishing a table with graphics fields on the Web. </p>
<p class=BodyText> </p>
<p class=Subheads>C++Builder
5: Some Useful New Features</p>
<p class=BodyText> Before
we end our short tour on Web programming with C++Builder, let's look at some
new features of C++Builder 5 that are useful in creating such applications. </p>
<p class=BodyText> </p>
<p class=BodyText> First,
the <i>TWebActionItem</i> object has a new <i>Producer</i>
property. This allows us to associate a content producer with a Web action
item, so we no longer need to write the <i>OnAction</i> event handler just to
indicate which producer is responsible for the HTML generation upon execution
of this action item. </p>
<p class=BodyText> </p>
<p class=BodyText> Second,
all page producer components in C++Builder 5 have a <i>StripParamQuotes</i>
property. This allows us to use content from HTML editors that automatically
place tag options inside a pair of quotation marks. </p>
<p class=BodyText> </p>
<p class=BodyText> Third,
now we can use packages when building ISAPI/NSAPI DLLs. In C++Builder 4, such
DLLs should be created only as single files. </p>
<p class=BodyText> </p>
<p class=BodyText> Also
note that if you want to recompile your C++Builder 4 Web applications with
C++Builder 5, you need to replace the reference to the <i>HTTPApp</i> header
file with a reference to the <i>WebBroker</i> header file: </p>
<p class=BodyText> </p>
<p class=Code><span class=Code><span Class=CodeGrn>#include
<condefs.h> </span></span></p>
<p class=Code><span class=Code><span Class=CodeGrn>#include
<stdio.h> </span></span></p>
<p class=Code><span class=Code><span Class=CodeGrn>#include
<stdlib.h> </span></span></p>
<p class=Code><span class=Code><span Class=CodeGrn>#include
<SysUtils.hpp> </span></span></p>
<p class=Code><span class=Code><span Class=CodeGrn>#include
<WebBroker.hpp> </span></span></p>
<p class=Code><span class=Code><i><span Class=CodeBlue>// #include <Httpapp.hpp> // C++Builder 4</span></i></span></p>
<p class=Code><span class=Code><span Class=CodeGrn>#include
<CGIApp.hpp> </span><i
style='mso-bidi-font-style:normal'><span Class=CodeBlue>// C++Builder 5</span></i></span></p>
<p class=Code><span class=Code><span Class=CodeGrn>#pragma
hdrstop</span></span></p>
<p class=Code><span class=Code><i><span Class=CodeBlue>/* TWebModule: DesignClass */</span></i></span></p>
<p class=Code><span class=Code>USEFORM("webfish1.cpp",
WebModule1); </span></p>
<p class=Code><span class=Code><i><span Class=CodeBlue>//
-------------------------------------------------------------</span></i></span></p>
<p class=Code><span class=Code><i><span Class=CodeBlue>// #define Application Httpapp::Application //
C++Builder 4</span></i></span></p>
<p class=Code><span class=Code><span Class=CodeGrn>#define
Application Webbroker::Application </span><i
style='mso-bidi-font-style:normal'><span Class=CodeBlue>// C++Builder 5</span></i></span></p>
<p class=Code><span class=Code><span Class=CodeGrn>#pragma
link "cgiapp.obj" </span></span></p>
<p class=Code><span class=Code><i><span Class=CodeBlue>//
-------------------------------------------------------------</span></i></span></p>
<p class=BodyText> </p>
<p class=BodyText> Finally,
let's examine the most innovative feature of the Enterprise version of
C++Builder 5: the InternetExpress components. These components are designed for
creating MIDAS clients that are Web applications. Such Web applications
exchange XML data packets with JavaScript-enabled browsers that play the role
of user front end. The details of creating such distributed MIDAS applications
are outside the scope of this article. However, using the InternetExpress
components isn't restricted to "pure" distributed applications; with these
components, we can create a Web application that is still a database client.
Such an application is more interactive than a traditional Web application
(such as that shown in Figure 12). We'll see why later. </p>
<p class=BodyText> </p>
<p class=BodyText> Let's
create a simple example that illustrates using InternetExpress components.
Since it's an example, we'll place the MIDAS server and MIDAS client in the
same application. To do this, create a new Web CGI application, and place the
Table and DataSetProvider components into the Web module. They represent the
"server" part of this application. Now set the <i>DatabaseName</i> and <i>TableName</i>
properties of the <i>Table1</i> component to BCDEMOS and Customers.db,
respectively. Then set the <i>DataSet</i> property of the <i>DataSetProvider1</i>
component to <i>Table1</i>. This makes <i>Table1</i> accessible to future MIDAS
clients. </p>
<p class=BodyText> </p>
<p class=BodyText> The next
step is to place the XMLBroker and MidasPageProducer components, which
represent the "client" part of our Web application, into the Web module. The
XMLBroker is responsible for getting data packets from MIDAS servers, and the
MidasPageProducer is responsible for generating Web content delivered to the
Web browser. Since the MIDAS server is inside the same application, set the <i>ProviderName</i>
property of the <i>XMLBroker1</i> component to <i>DataSetProvider1</i>, leaving
its <i>RemoteServer</i> property blank (see Figure 21). </p>
<p class=BodyText> </p>
<p class=Captions> <img
width=250 height=211 src="images/cb200006ne_f_image038.jpg" tppabs="http://www.cbuilderzine.com/features/2000/06/cb200006ne_f/cb200006ne_f_image038.jpg"><br>
<b>Figure 21:</b>
The WebModule of our InternetExpress demonstration application. </p>
<p class=BodyText> </p>
<p class=BodyText> Now
select Web Page Editor from the pop-up menu of the <i>MidasPageProducer1</i> component.
This property editor allows us to define which components should be shown in
the browser for presenting and editing data. This is done by creating branches
in the treeview-style control in the upper-left corner of the editor's form.
For example, let's place a DataForm component, with FieldGroup and
DataNavigator components inside it. We also need to set the <i>XMLBroker</i>
property of the <i>FieldGroup1</i> component to <i>XMLBroker1</i>, and set the <i>XMLComponent</i>
property of the <i>DataNavigator1</i> component to the <i>FieldGroup1</i> (see
Figure 22). </p>
<p class=BodyText> </p>
<p class=Captions> <img
width=250 height=294 src="images/cb200006ne_f_image040.jpg" tppabs="http://www.cbuilderzine.com/features/2000/06/cb200006ne_f/cb200006ne_f_image040.jpg"><br>
<b>Figure 22:</b>
Creating the user interface with the Web Page Editor. </p>
<p class=BodyText> </p>
<p class=BodyText> The next
step is to set the <i>IncludePathURL</i> property of the <i>MidasPageProducer1</i>
component. It's a path where our Web application can find JavaScript and HTML
files, which are used to produce the HTML content. The *.js and *.html files
should be copied from the \<i>Cbuilder5\Source\Webmidas</i> directory to this
URL.</p>
<p class=BodyText> </p>
<p class=BodyText> It should be pointed out that the \Inetpub\Scripts
directory, which is the default script directory of Microsoft IIS, and a
potential place to store our InternetExpress application, is not a valid place
for these files. The reason is that by default any file of this directory can
be executed, but cannot be read. Therefore, it is necessary to change the
default settings for this directory, or - better yet - to use another URL to
store these files.</p>
<p class=BodyText> </p>
<p class=BodyText> The last
step is to create a <i>TWebActionItem</i> object, set its <i>Default</i>
property to True, and set its <i>Producer</i> property to the <i>MidasPageProducer1</i>.
Our application is almost ready to use; we just need to uncheck the Use
dynamic RTL option on
the Linker page of the Project Options dialog box. Once this is done, save and
compile the project, and place it in the scripts directory. Now we can test the
application. The result is shown in Figure 23. </p>
<p class=BodyText> </p>
<p class=Captions> <img
width=250 height=378 src="images/cb200006ne_f_image042.jpg" tppabs="http://www.cbuilderzine.com/features/2000/06/cb200006ne_f/cb200006ne_f_image042.jpg"><br>
<b>Figure 23:</b>
The demonstration application in action. </p>
<p class=BodyText> </p>
<p class=BodyText> Earlier,
I promised to explain why this application is more interactive than the one
shown in Figure 12. In terms of Microsoft Windows DNA requirements,
interactivity means that the front-end application can process user input
without calling a server. As you'll recall, the application shown in Figure 12
must connect to the Web server, and call the Web application when the user
posts a single record. To call Web applications after any user operation is a
typical feature of HTML-based Web applications. From this aspect, the
interactivity of such applications is poor. </p>
<p class=BodyText> </p>
<p class=BodyText> The
behavior of our InternetExpress application is different. Using it, you can
edit several records, move between them, use the Undo or Post buttons, append or delete records,
with none of these operations requiring a connection to the Web server. Only
pressing the Apply Updates button results in running the Web application again. This
operation forces the Web application to save the edited data - perhaps several
records - to the database. </p>
<p class=BodyText> </p>
<p class=BodyText> If we
look at the source of the Web page generated by this application, we see that
it contains some JavaScript code, as well as XML data corresponding to the
table contents. (Its size is limited by the <i>MaxRecords</i> property of the <i>TXMLBroker</i>
component.) Since JavaScript is interpreted by a browser, and all necessary
data is cached in the Web page, there's no need to call the Web server when
moving among records, unless you need to download the next portion of records
from a database. This makes InternetExpress applications more interactive than
HTML-based applications. </p>
<p class=Subheads> </p>
<p class=Subheads>Conclusion</p>
<p class=BodyText> Thus, C++Builder
allows us to create different types of Web applications for obtaining and
publishing data. And in a relatively simple way. </p>
<p class=BodyText> </p>
<p class=BodyText> <i>The project<b> </b>referenced in this article is<b
style='mso-bidi-font-weight:normal'> </b>available for <a href="download/cb200006ne_f.zip" tppabs="http://www.cbuilderzine.com/features/2000/06/cb200006ne_f/cb200006ne_d.asp">download</a>. </i></p>
<p class=BodyText> </p>
<p class=BodyText> </p>
</td>
</TR>
</TABLE>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -