The Developers Group Magazine March/April 2006 Page 1 return to index
Delphi and AJAX
by Marco Cantù
Asynchronous JavaScript XML is not really a brand new web technology, but its usage is rapidly changing
the way users perceive web applications. If the browser is becoming a platform, can Delphi fit into this
new model? The flexibility of WebBroker and the strengths of the database connectivity make Delphi a
very good choice for an AJAX-based server.
What is AJAX?
Until a few months ago, I used to associate the term AJAX with one of the most famous Dutch football teams.
Over the last few months, however, I’ve kept seeing more and more astonishing web sites, based on standard
technologies (HTML, CSS, JavaScript), mostly browser independent, featuring rich client applications! If
you want to see an overall description of AJAX and the underlying technologies, refer to the key references
at http://www.adaptivepath.com/publications/essays/archives/000385.php.
The AJAX term was invented in February 2006, but certainly is was Google adoption of the technology that
has been critical to its spreading. Google is not the only company using it, though. There are countless sites
featuring it, including the short list of AJAX-based sites below. Be sure to visit these sites to get a feeling of
the power of this technology:
Google Suggests (http://www.google.com/webhp?complete=1&hl=en)
Gmail (http://gmail.google.com/, feel free to email me on marco.cantu@gmail.com if you want an invitation)
Google Maps (http://maps.google.com/)
Protopage (http://www.protopage.com/)
Press-display (http://www.pressdisplay.com/pressdisplay/viewer.aspx)
Ta-da Lists (http://www.tadalist.com/)
Microsoft’s experimental AJAX site at start.com (http://www.start.com/). Notice in particular how you can
drag and drop the portions of the page to rearrange them.
AJAX in Delphi
Needless to say I’ve started playing with AJAX myself. I’ve found a very rich engine for query processing
(also very easy to use) at Ajax Toolbox (http://www.ajaxtoolbox.com/) and I’ve done some experiments
with my newsgroup front-end (beta) web site at http://dev.newswhat.com. If you go to a thread you can
open individual messages, fetching them one by one without refreshing the page. A similar example is in my
blog site, if you follow the link to the Comments List (http://blog.marcocantu.com/blog_alltalkback.html)
in the main menu. You’ll see a list of talkback messages and can open each of them directly in the page. These
examples use AJAX on top of Delphi-driven applications but the architecture of these applications is too
complex to describe here.
This is why I’ve also built a simple Delphi AJAX demo (for a Birds-of-a-Feather session I did at BorCon 2005)
that I’m going to discuss in detail here. For the development of this project I’ve built a Delphi CGI WebBroker
application (to keep things simple) and used two different JavaScript libraries: www.ajaxtoolbox.com for the
AJAX communication and Google’s own JavaScript XML, XPath, and XSLT engine at sourceforge.net/
projects/goog-ajaxslt for XML processing.
The goal of this demo is to display database data dynamically and combine master-detail data over web
pages without sending too much data to the client upfront.
The Web Page
The demo has only one web page, used to display different types of data. First of all, it includes a set of
JavaScript files:
<script language=”JavaScript1.2"
src=”/include/AjaxMdDemo.js”> </script>
<script language=”JavaScript1.2"
src=”/include/AjaxRequest.js”> </script>