Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Computing
Conference & Expo
November 2-4, 2009 NYC
Register Today and SAVE !..
SYS-CON.TV
Today's Top SOA Links


The Object Of It All
The Object Of It All

  • There are lots of ColdFusion developers out there - that's good for us.
  • There are also lots of ASP developers out there - that's good for them.
  • ColdFusion developers are empowered with multiple ways to extend the
        ColdFusion language - that's good for us.
  • ASP developers are not as lucky - that's bad for them.
  • ASP developers rely on COM objects to extend ASP - that's good for us.
  • That's good for us? Yes, most definitely. ASP has no built-in functionality for many simple things that are built into ColdFusion, so ASP developers use COM objects extensively, even for those little things that we CFers take for granted: generating SMTP e-mail messages, for example. To generate e-mail, ASP developers must install third-party components that provide them with that functionality.

    So why is this good news for us? Well, the good news is that there are hundreds of third-party components out there, offering all sorts of functionality. Some are freebies. Others are shareware or commercial software. And ColdFusion developers can take advantage of them all.

    This column won't teach you how to write your own COM objects. It will, however, teach you how to use COM objects and how to convert the sample ASP code that accompanies most COM objects into CF code. Note that the examples here use an excellent graphing object, AspChart, that allows you to create professional and flexible charts on the fly in several file formats. AspChart is created by ServerObjects Inc. (www.serverobjects.com). The president of ServerObjects is Stephen Genusa, one of the leading authorities on ASP development.

    Understanding COM Objects
    COM, the acronym for Component Object Model, is a software specification designed to allow applications to dynamically link components at runtime. This means that developers can encapsulate functionality into clean, published components and then allow other applications to interact with them. In other words, COM objects are a way to create black-boxed reusable components that other developers can take advantage of.

    COM objects are usually DLL or EXE files and can be written in almost any language imaginable, such as C/C++, Visual Basic, Java and Delphi. Once the object is written, it's installed and registered on the computer it will be used on. Registering the COM object publishes it (and its interfaces) to other applications so they can use it.

    Almost all COM objects come with installation and registration instructions. Those instructions are the same regardless of the application using the COM object.

    Instantiating COM Objects
    To use an installed COM object, the first thing you have to do is initialize it for use. Usually this involves instantiating the object.

    To initialize COM objects in Cold Fusion, you use the <CFOBJECT> tag, which takes the name of the object as an attribute and a name that you use to refer to that object once it's been initialized. The code to initialize AspChart looks like this:

    <CFOBJECT ACTION="CREATE" NAME="Chart" CLASS="ASPChart.Chart">

    In this example the <CFOBJECT> tag is creating an instance of the chart object. The object's name is "ASPChart.Chart" (every object has a unique name) and it is passed in the CLASS attribute. <CFOBJECT> instantiates the object, which can now be referred to as "Chart" as specified in the NAME attribute. Just as a point of reference, here's the ASP code that does the same thing:

    Set Chart=Server.CreateObject("ASPChart.Chart")

    As you can see, converting the sample ASP instantiation code to ColdFusion code is pretty simple.

    Setting Object Properties
    Now that the object is instantiated, we need to pass values to it. COM object values are called properties, and every COM object has a different set of properties. Refer to the object documentation for a list of properties and their values.

    Two of AspChart's properties are Height and Width. These specify the size (in pixels) of the image to be generated. The ASP code to set these properties is:

    Chart.Height=300
    Chart.Width=500

    ColdFusion programmers set object properties with the familiar CFSET tag. To set the same two properties with the same two values, your code would look like this:

    <CFSET Chart.Height=300>
    <CFSET Chart.Width=500>

    As you can see, converting ASP property-setting code to ColdFusion code is also pretty simple.

    Setting Object Subproperties
    Some properties contain subproperties. For example, AspChart lets you specify the font information to use for the chart title. The ASP code to set the size and font name would be:

    Chart.ChartTitleFont.Size=20
    Chart.ChartTitleFont.Name="Times New Roman"

    ColdFusion doesn't let you set subproperties directly. Instead, you have to first define a variable that points to the property, then set the subproperties within that new variable. To demonstrate this technique, the following code sets the same two subproperties as the ASP code above:

    <CFSET ChartFont=Chart.ChartTitleFont>
    <CFSET ChartFont.Size=20>
    <CFSET ChartFont.Name="Times New Roman">

    ChartFont is a temporary variable that points to the Chart.ChartTitleFont property. ChartFont.Size thus points to the Size subproperty within the ChartTitleFont property. Once again, as you can see, with a little effort, converting ASP subproperty-setting code to ColdFusion code is pretty easy to do.

    Invoking Object Methods
    The last thing you need to know is how to invoke object methods. A method is a function within a COM object. Whereas properties set values within an object, methods actually execute the function using any properties already set. (For this reason, methods are almost always invoked after all the properties have been set.)

    Every COM object has at least one method, and some have many more. The code to invoke an object method in ASP looks like this:

    Chart.SaveChart

    This invokes the AspChart SaveChart method that actually creates the image file based on all the properties already set. The equivalent ColdFusion code is:

    <CFSET temp=Chart.SaveChart()>

    From ColdFusion's perspective, the only difference between setting a property and invoking a method is that methods must have () characters after the method name (methods are essentially functions, and ColdFusion uses () to distinguish functions).

    Some methods take one or more parameters. To pass parameters to a method in ColdFusion, just specify them in a comma-delimited list between the "(" and ")" characters. That's all there is to it. Pretty simple indeed.

    Where to Go from Here
    Now that you know how easily ColdFusion developers can take advantage of COM objects and COM technology, here are some useful sites for you to visit:

  • The Microsoft COM Technologies home page is at www.microsoft.com/com. This is a great place to learn more about COM and there are also plenty of links to COM objects and vendors.
  • ServerObjects Inc. have created a whole set of COM objects (AspChart is one of many). Their home page is at www.serverobjects.com.
  • The CNET ActiveX page at www.activex.com has lists of hundreds of COM objects, with reviews and recommendations as well.

    For more information about ColdFusion's COM support, the <CFOBJECT> tag and writing COM objects, see the chapter entitled "Interfacing with COM and DCOM Objects" in my book ColdFusion Web Application Construction Kit (ISBN 07897-14140).

    About Ben Forta
    Ben Forta is Adobe's Senior Technical Evangelist. In that capacity he spends a considerable amount of time talking and writing about Adobe products (with an emphasis on ColdFusion and Flex), and providing feedback to help shape the future direction of the products. By the way, if you are not yet a ColdFusion user, you should be. It is an incredible product, and is truly deserving of all the praise it has been receiving. In a prior life he was a ColdFusion customer (he wrote one of the first large high visibility web sites using the product) and was so impressed he ended up working for the company that created it (Allaire). Ben is also the author of books on ColdFusion, SQL, Windows 2000, JSP, WAP, Regular Expressions, and more. Before joining Adobe (well, Allaire actually, and then Macromedia and Allaire merged, and then Adobe bought Macromedia) he helped found a company called Car.com which provides automotive services (buy a car, sell a car, etc) over the Web. Car.com (including Stoneage) is one of the largest automotive web sites out there, was written entirely in ColdFusion, and is now owned by Auto-By-Tel.

  • In order to post a comment you need to be registered and logged in.

    Register | Sign-in

    Reader Feedback: Page 1 of 1

    very good articles, I used to be able to see all the article, now I only see the first page of articles :(


    Your Feedback
    Amer wrote: very good articles, I used to be able to see all the article, now I only see the first page of articles :(
    Subscribe to the World's Most Powerful Newsletters
    Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
    Click to Add our RSS Feeds to the Service of Your Choice:
    Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
    myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
    Publish Your Article! Please send it to editorial(at)sys-con.com!

    Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

    SYS-CON Featured Whitepapers
    ADS BY GOOGLE