Delphi Handbooks Collection


Delphi XE Handbook


Delphi 2010 Handbook


November 23, 2006

Google Gadgets... Written in Delphi

Google Gadgets are small areas on web pages hosted by Google Personalized home page, whcih can use AJAX and a Delphi/Kylix backend.

As a compendium to some of the theory about Web development (see my latest blog entry) with the REST / AJAX model, which Delphi can fully support, I've recently built a Google Gadget for the Google Personalized Home Page. This gadget shows data from the classic Customer demo table, as you can see by installing it. Simply go your personalized home page (you'd need to create one) and install this gagdet. You can see the sample output below.

customer's gadget

You can select the edit option and pick a country. The country parameter is used by the gadget to create a proper REST call, like ajax.marcocantu.com/scripts/customers?Country=US. Using this link you can actually see the underlying XML returned by the REST server, which is written in Delphi... and simply formats in XML the result of a parametric query.

The gadget (the complete code is listed in the gadget's XML, linked above) performs an AJAX request on my server and than formats the output by creating an HTML string in JavaScript. This is the core of the code (I've removed some of the code for simplicity):

       _IG_FetchXmlContent(strUrl,
function (response) {
var compList = response.getElementsByTagName("customer");
for (var i = 0; i < compList.length ; i++) {
var value = compList.item(i).firstChild.nodeValue; // get the first node, the text node
html += "<span style='text-align:left;font-size:70%'>" + value + "</span><br>";
if (i % 12 == 11) {
html += "</td><td valign='top'>";
}
}
html += "</td></tr></table>";
html += "</div>";
_gel('content__MODULE_ID__').innerHTML = html;
});

This is all. Now what is relevant about this demo? You can have a Delphi backend (with database access and XML processing code) to provide data to a Google Gadget. In the real world, this means you can provide a summary /manager's view of the key data of a company (sales in the last few days or weeks, key financial indicators, and the like) that are hosted by a standard home page, and don't require users jump to and login to a specific web site. You can also grab data from any other web site and provide a summary in a gadget.

Google is not the only one offering similar capabilities, with Yahoo and Microsoft's Live offering a similar home page customization. Google's API for gadgets is very rich, though, and Im' not sure if the other portals match it.





 

5 Comments

Google Gadgets... Written in Delphi 

Hi Marco,

Very interesting! The source for your REST server 
that compleats the ensemble would be very useful to 
see how the whole package works :-)

Cheers,
Raymond.
Comment by Raymond on November 26, 22:18

Google Gadgets... Written in Delphi 

 This is the third time that I've been struggling of a
simple solution only to find you providing it for me.
I'd love to see some more about this, it would also be
nice at the CodeGear conference (whenever that is) 
Comment by Ray Andrews on November 29, 17:18

Google Gadgets... Written in Delphi 

yes, the server source would be nice; been looking a 
while for examples on how to do this.

many of the gadgets i have downloaded appear to be 
more than just simply xml queries. could you please 
do a more advanced one that interacts with the user?

thanks!
Comment by n/a on June 6, 10:47

Google Gadgets... Written in Delphi 

But, where is the Delphi part?
Comment by Bruce on December 13, 05:59

Google Gadgets... Written in Delphi 

 may i have any source code for use gadget in delphi?
Comment by farid on September 6, 17:23


Post Your Comment

Click here for posting your feedback to this blog.

There are currently 0 pending (unapproved) messages.