A Sip From The Firehose: May 19, 1996

By: David Intersimone

Abstract: For the first recipe we'll bake an Internet Browser with Delphi 2.0

Sunday, May 19, 1996
La Selva Beach, California

For the first recipe we'll bake an Internet Browser with Delphi 2.0

Over the weekend I took some downtime from my travels and watched one of those cooking shows on TV. While watching it dawned on me that what programming was missing was a good cookbook. In today's Sip from the Firehose I am starting what will become known as "Betty Hacker's Down Home Developer's Cookbook". For the first recipe we'll bake a fresh blackberry Internet Browser with Delphi 2.0. To start your own cookbook just cut and paste the recipe included below.

Betty Hacker's Quick 'n Easy
Fresh Blackberry Internet Browser
Delphi 2.0

Even when fresh Internet components are not in season, you can still enjoy a bubbly hot blackberry Internet browser in just a few seconds with only 5 lines of Delphi code.

9 pounds Microsoft Internet Control Pack (beta 2)
3 tablespoons Delphi interface files for MS Internet Control Pack
1 blank Delphi form
1 ounce TPanel
1 teaspoon TButton
1 tablepoon TComboBox
5 teaspoons sample browser code
1 cup fresh blackberries
1 cold beverage

Preheat your PC to 110 volts (220 volts for most developers outside the US).

Stir in the Microsoft Internet Control Pack: Download and install the Microsoft Internet Control Pack (beta 2) from Microsoft's Web site. Note: the size of the control pack is 2mb!

Blend the Microsoft Internet Control Pack into the Delphi component library...

Whip up the Delphi 2.0 interface files: Download the Delphi 2.0 interface files to support the MS Internet Control Pack. Note: the size of the zip file is only 29k. Unzip ICP.ZIP to a temporary directory. Correct the registry by importing the msicp.reg file (contains a registry key which is missing from the MS distribution registry) using the registry editor (RegEdit).

Blend the Microsoft Internet Control Pack into the Delphi component library: Copy msicpb.pas (contains wrapper classes for the eight MS ActiveX Internet controls), msicpb.dcr (resource file containing a component palette icon for msicpb), and olectrls.dcu (updated OLE Control support unit) from the temporary directory to your Delphi 2.0lib directory. Run Delphi 2.0. Select Components | Install, click the Add button, type msicpb, and then press OK to recompile the component library. Note: This will add the eight Microsoft ActiveX Internet control icons into Delphi 2.0's OCX component palette page.

Cook and stir the Internet browser: Select File | New Application.

Mix in a Panel: From the Standard component palette page drop down a Panel control. Clear the Caption property (size the panel to taste). Set the Align property to alTop.

Blend in a Button and a ComboBox into the Panel: From the Standard component palette page drop a Button and a ComboBox on Panel1 (arrange to taste). Set Button1's caption property to &Go and its default property to True. Clear the text property of ComboBox1. Widen ComboBox1 to taste. Multi-select the ComboBox and the Button. Right-mouse click, and pick the Align menu item. Pick the Vertical | Center in Window option. Click OK.

Fold in an HTML ActiveX control: From the OCX component palette drop down one HTML control. Size the HTML control on the form to taste.

Toss in some code to give the browser navigation and history list functionality: Double-click on the Go button. Type in
At this point the Browser is fully functional, but I'll add some code to implement the history list using the ComboBox. Select the HTML control. Pick the events page in the object inspector. Double-click on the OnBeginRetrieval event. Add the following code:
     if ComboBox1.Items.IndexOf(HTML1.URL) < 0 then
     ComboBox1.Text := HTML1.URL;

Bake approximately 3-5 seconds or until the browser is golden brown.

Note: For now you must turn off integrated debugging to use the beta versions of Microsoft's Internet controls. To turn off integrated debugging, select Tools | Options, and click off Integrated Debugging in the Debugging Section of the Preferences tab.

Bake (hit the F9 key) approximately 3-5 seconds or until the browser is golden brown. Serve warm with the fresh blackberries and the cold beverage of your choice. Type an URL into the ComboBox and hit the Enter key. Navigate around the web. Drop down the ComboBox arrow and notice that the browser is saving unique URL's in the ComboBox list of items.

One Blackberry Internet Browser per developer.

Fresh Blueberry Internet Browser: Substitute one cup blueberries for the blackberries.

Fresh Blackberry Internet Browser OLE Automation Server and Controller: Delphi 2.0 supports both OLE Automation Servers and Controllers. What better way to illustrate this than by extending the browser to be an OLE Automation Server and then build an Automation Controller to drive it. Use the following cooking instructions to add the server support and create the controller.

Simmer the fresh blackberry browser: From Delphi choose File | SaveAll. Save the unit file as Mainunit. Save the project file as WebApp.

Fold an automation object into the browser: Choose File | New to bring up the object repository. Double-Click on the Automation Object (brings up the OLE Automation Server Expert). Type TAppObject into the class name edit box (the OLE class name will be filled in automatically as WebApp.TAppObject). Type in a description for your blackberry browser. Leave the Instancing ComboBox set to Multiple Instance. Click the OK button to close the expert.

Blend in the declaration of the automation method: Add a method declaration to the automated section of the TAppObject class declaration:
     procedure GotoPage (PageName: string);
The automated section contains the methods and properties we want to expose through OLE Automation. The line of code above creates a GotoPage method that will select a given HTML page.

Toss in the code to implement the method: After the Implementation keyword add the following lines of code:
     uses Mainunit;
     procedure TAppObject.GotoPage(PageName: string);

Simmer (hit the F9 key) the OLE Automation Server enhanced Fresh Blackberry Internet Browser: Your server automatically enters itself in the system registry and is running and ready to be controlled.

Beat in an OLE Automation Controller for the Browser: From Delphi, File | SaveAll the browser server project. Save the automation unit file as Autounit. Choose File | New Application to start the browser automation controller. Shrink the form down to a size small enough to hold a Button and an Edit box. Drop down an Edit box at the top center of the form. Widen the Edit box to taste. Clear the Text property of the Edit box. Drop down a Button below the Edit box. Change the Button caption to 'Goto'. Double Click on the Button to add the event handling code. Add the following lines to make the implementation of the Button click method look like the following:
     procedure TForm1.Button1Click(Sender: TObject);
       Browser: Variant;
       Browser := CreateOleObject('WebApp.AppObject');

Sprinkle a little sugar on the controller: Add a uses OleAuto; statement right after the unit's implementation keyword.

Bake (hit the F9 key) the OLE Automation Controller: type a URL into the Edit box. Click the Goto Button and watch the Fresh Blackberry Internet Browser Automation Server display that page.

Look for further additions to the cookbook in future editions of Sip from the Firehose (or SipFH as some of you are calling it in your email correspondence). Maybe I should create my own Sunday morning "Cooking with Betty Hacker" TV show? If you have developer recipes of your own, send them along.

Happy Cooking!

Server Response from: ETNASC02