[1] [2] [3] [4] [5]

Getting HTML religion

As you can probably tell if you’ve worked with Word 95 and Word 97 at all, the first sample is definitely Word 95 Basic.  All of the code in these samples works very well in Word 97, although other developers have not been as fortunate when they ported their Word 95 macros.

I probably won’t bother porting FRX2DOC to Word 97’s new object model, powerful and intriguing as it is.  My reason is simple: last year, when I wrote this code, HTML was one format among many. Now it is the format on which I will concentrate, for all the reasons I’ve already spelled out – and it’s difficult to justify spending a lot of time learning to automate Word 97 for output that may very likely end up in HTML format anyway.

It’s more likely that I will revise the code in FRXCLASS and FRX2HTM in the near future, because creating HTML, and not using FRXs, is now my primary aim. To fulfill this aim, I will extract the code in FRX2HTM that handles the HTML formatting and tagging from FRX2HTM to a separate, custom object with which an FRXCLASS subclass can collaborate when necessary. 

This revision will allow my HTML-emitting code to be available to VFP output that doesn’t necessarily need the data management capabilities of the underlying .FRX event drivers. Many VFP reports handle the information in a single record, and do not scan through tables or requiring grouping at all.

VFP Does Web Sites

Another technique, which allows very sophisticated formatting and complete control within VFP, is to create your own set of meta-tags, or instructions about HTML instructions, which are then interpreted by a VFP program to generate the final HTML result. This is like creating a custom sort of TEXTMERGE, with delimiters that contain special instructions beyond the TEXTMERGE delimiters’ meaning of „evaluate the contained expression“.  In other words, your custom delimiters can mean „evaluate the contained expression according to some extra rules, denoted by symbols or keywords, which are part of the expression.“

Colin Nicholls and Cornerstone Software have written a WebSpinner program to generate web pages and organize the pages and links by site, which makes use of this technique. In addition to allowing you to highlight blocks of text and choose to enclose to enclose the highlighted block in a standard web tag, like most HTML-editing software, WebSpinner allows you to specify custom delimiters, which will then be used for expressions contained special WebSpinner terminology.  For example, the following text expresses a link and contains two nested WebSpinner expressions:

<A HREF={THIS.Parent.Href}> {ICON MyIcon} </A>

The first delimited expression tells WebSpinner to replace it with the URL of the page designated as the current parent’s Parent page in a standard „outline“ site organization (you can see how WebSpinner conveys the organization of web pages as a site outline in the figure below). The second expression tells WebSpinner that there is an object designated as „type Icon“ for this project/site with the reference name „MyIcon“, and that WebSpinner should insert the relevant filename here.  The resulting HTML might look like this:

<A HREF=“intro.htm“> „logo.gif“ </A>

WebSpinner, a VFP application to generate web pages and web sites by Colin Nicholls, using Internet Explorer to „preview“ its results.

WebSpinner also uses a „macros“ concept to allow you to fulfill more complex requirements with a single keyword.  For example, since a hypertext link to a „parent document“ is a common requirement, you might define a WebSpinner macro with the name „JUMP TO PARENT“ and define that macro as follows:

{#IFDEF THIS.Parent}
   <A HREF={THIS.Parent.Href}> {ICON MyIcon} </A>

...now you’d be able to get the appropriate link in your document by typing {JUMP TO PARENT}.

WebSpinner is not a commercial product.  It was written to match Cornerstone’s own needs, and it may be idiosyncratic. You may not find WebSpinner’s particular methods of enhancing HTML production to your taste, so you may devise an entirely different system.  However, this application shows you the level of complexity that can be achieved, entirely within VFP, for web site design and generation as well as any other text-based output.

You can emit complex HTML more easily by using an inner system of templates and definitions like these, or with an HTML-knowledgeable class like FRX2HTM to control the formatting details. Whether you design systems in which a sophisticated user creates report designs interactively (which is essentially what WebSpinner is), or whether your system handles all details of report design programmatically is not the issue. You can see the tremendous possibilities.

It’s all made possible by VFP’s ability to handle strings, generate text, and then to assemble the resulting text files into coherent, searchable, updatable document collection – as only a full-fledged database management system can. 

I assert here, quite seriously, that Visual FoxPro and applications you write in Visual FoxPro may be uniquely qualified to provide Web document editing and production facilities! I say this partly because of the text-handling capabilities I’ve already alluded to, but also because the information for a large, complex site has to come out of a database in the first place to be maintainable.  In the WebSpinner macros above, we have tables of icon filenames defined to play particular roles in the site’s pages, tables of content, tables of content relationships and tables of styles and expandable macro expressions...  and this is a relatively simple example.

How we display HTML
(translation: how we preview and possibly print reports)

The figure displaying WebSpinner above also shows the way WebSpinner „previews“ its generated results for the web designer: it calls a browser to display the page. Although the browser in the figure is Internet Explorer, WebSpinner does not concern itself with this context information; it simply passes a filename to the operating system and expects the OS to deliver it to the right „owner“, using the principles and a technique that I referred to earlier.  Here’s Colin’s code for achieving this result:

* by Colin Nicholls

*//   Declare the ShellExecute() API function:

declare long ShellExecuteA in SHELL32 ;
   long, string, string, string, string, long

*//      Invoke the shell to open the file:

local lnReturnValue
lnReturnValue = ShellExecuteA( 0, "open",  ;
                      m.tcFilename, "","", 1 )
if m.lnReturnValue < 33
   =Messagebox("Error " + ;
               alltrim(str(m.lnReturnValue)) ;
               + " was returned from ShellExecute(). ";
               + "The requested file could ";
               + "not be opened.", ;
                MB_ICONSTOP, c_APP_TITLE)

This method can be used to fulfill the inevitable „report preview“ requirement in any VFP application that uses HTML format to provide output, not just applications like WebSpinner that are specifically designed to maintain web sites.  From this „preview“ in the user’s browser, the user can then decide to print the document as required.

If you want a preview (or multiple previews!) within VFP, you can use the Microsoft Web Browser ActiveX control, shown taking up all the real estate in a form in the figure below. With this control (which is of class Shell.Explorer.1, according to my Properties window), no more code than you see in the figure is required to show an HTML file and then refresh it after its contents have changed. You’ll find this form included as BROWSE.SCX in your source code.

The Microsoft Web Browser ActiveX control provides „report preview“ within a VFP form. (BROWSE.SCX)

The „preview form“ I’m showing here does not happen to have any VFP controls on it. One thing that’s glaringly missing is a „Print“ button.  I haven’t figured out how to cause this OCX to send its current contents to the printer, and the Web-based world in general does not pay a lot of attention to the problem of delivering hard copy.  It’s possible that I could use Automation to control the InternetExplorer.Application or Netscape.Network.1 or some similar class, loading the appropriate filename into it and telling it to print, but I haven’t found a way, yet.  (I believe there is such a method for IE4, and also that the OCX connected with the new HTMLHelp engine exposes this printing mechanism.)

I haven’t yet found a lightweight applet or ActiveX for Windows whose function is to interpret HTML and send it to the printer with no visible interface.  There exists at least one for the Macintosh. I’ll keep surfing the ‘Net until I find one I can use!

In my current system, Word appears to handle HTML better for printing than any other application. (It’s probably not accidental that the Microsoft Fax transport uses Word to render an HTML-type document attachment when you add one to a faxed message.) So, for now, if I needed to print my current HTML output, and if it wasn’t sufficient to send the output to a browser and have the user print from there, I’d Automate Word for this task , load this file with the appropriate filter to let Word know that this was an incoming HTML-formatted document, and tell Word to print it.

[1] [2] [3] [4] [5]