4.3.9 Internet

Internet

There is no doubt that the Internet has become the driving force in the software industry. A number of new Internet-related features have been introduced in Visual FoxPro 6.0. However, public opinion still seems to be that there should have been more. Well, there are more! Just check out this category.

Cookies Class

Class

_cookies

Base class

Custom

Class library

_internet.vcx

Parent class

_custom

Sample

None

Dependencies

_base.vcx

One of the standard problems on the Internet is identifying users; one resolution to this problem is to assign cookies to users. In this case, a small file is stored on the client's computer. This file basically stores an ID you can use later on to identify the user. On the server side, this ID must be stored in a table so you can figure out what ID belongs to what user. Cookies can be used only if the client's browser supports cookies and the user has turned this feature on (which should be standard, in my opinion). For more information about cookies, see Rick Strahl's book Internet Applications with Visual FoxPro 6.0.

DBF-> HTML

Class

_dbf2html

Base class

Custom

Class library

_internet.vcx

Parent class

_custom

Sample

...\Samples\Vfp98\Solution\Ffc\dohtml.scx

Dependencies

_base.vcx

This class creates HTML output based on a DBF file. The class is a simple wrapper for the GENHTML program, which ships with Visual FoxPro 6.0. To use the class, open a data source, instantiate the DBF->HTML object and call the GenHTML() method:

USE Customer

oDBF2HTML = NewObject("_dbf2html","_internet.vcx")
oDBF2HTML.GenHTML()

This creates an HTML file called Customer.htm, which is immediately displayed in your standard Web browser. Figure 23 shows the created output.

By default, the class uses the current alias and creates an output file of the same name as the current table (with an HTM extension). The file is then displayed immediately, using the default Web browser. You can change this behavior through a couple of properties. The property lUseCurrentAlias specifies whether the currently selected alias should be used. If this property is set to .F. or no valid data source is selected, the cSource property specifies an alternative source. The properties lAutoNameOutput and cOutFile do the same for the created output. If the lAutoNameOutput property is set to .T., the output file gets the same name as the used data source (with an HTM extension). If this property is set to .F., the cOutFile property specifies the file name.

Figure 23. An HTML table based on a simple DBF created by the DBF->HTML class.

 

The nGenOutput property specifies how (and if) the created output file should be displayed. By default, the default class browser is displayed. Figure 23 shows Internet Explorer used as the Web browser. Table 8 explains the possible values of nGenOutput.

Table 8. Possible values for the nGenOutput property.

Value

Description

0

Generates an output file. The file is created and stored, but it is not displayed.

1

Generates the output file and display it using the Visual FoxPro editor using the MODIFY FILE command.

2 (default)

Generates output file and displays it in the standard Web browser.

3

Generates a file and asks the user what to do with it (see Figure 24).

4

Generates a file and instantiates a public _oHTML object. You can make this object visible like so:

_oHTML.Show()

5

Instantiates a public instance of the _oHTML object, but no output file is generated.

Figure 24. The Save As HTML dialog box as used by all HTML foundation classes.

By default, all records from the entire data source are printed, but you can limit this using the cScope property. This property is of type character. Its value is simply evaluated in the scan-loop that iterates through the table. The value could be blank, "NEXT 1", "Country = 'Austria'" or the like.

You can alter the look and feel of the table, specifying your own output styles using Genhtml.prg. The name of a certain style can be specified in the cStyle property. A description of this table is beyond the scope of this book.

As mentioned, the DBF->HTML class uses Genhtml.prg to create the HTML output. If you want to change the behavior of this class, you most likely have to change this program. You can specify your own genhtml program by setting the _GENHTML system variable. However, there are some minor features the DBF->HTML wrapper doesn't support. You can subclass the DBF->HTML class to add those features or to support your own Genhtml.prg. The only method this class has is GenHTML(). This method is relatively trivial and simple to change or overwrite.

FRX->HTML

Class

_frx2html

Base class

Custom

Class library

_internet.vcx

Parent class

_custom

Sample

...\Samples\Vfp98\Solution\Ffc\dohtml.scx

Dependencies

_base.vcx

The FRX->HTML class is essentially the same as the DBF->HTML class. The only difference is the source, which is not a DBF but an FRX report. Note that, due to essential paradigm differences, many report layout features don't convert well to HTML format.

See above (DBF->HTML) for more details.

Hyperlink Object

Class

_hyperlinkbase

Base class

Hyperlink

Class library

_hyperlink.vcx

Parent class

_hyperlink

Sample

...\Samples\Vfp98\Solution\Ffc\hyperlnk.scx

Dependencies

_base.vcx

The Hyperlink object is used by all the Hyperlink interface classes. This class provides all Web navigation functionality. It is based on the native Visual FoxPro Hyperlink class. However, it does not use the default hyperlink behavior a lot. The class first queries the standard Web browser, and if it is Internet Explorer, the browser is instantiated as a COM server to gain more control. The Hyperlink base class initially was designed for use in active documents, where it works great. However, the class can still be used in regular Visual FoxPro applications. The problem is that the Hyperlink base class fires up a new instance of the default Web browser every time the NavigateTo() method is called. This is not what most programmers want. Typically, one wants to navigate using the same instance of the Web browser. The Hyperlink object foundation class provides this behavior. However, you can still navigate using separate browser instances if you want (see below).

The Hyperlink object has two different methods that can be used to navigate to a URL. One is the native NavigateTo() method, and the other is a custom method called Follow(). The Follow() method cannot handle parameters. It simply navigates to a location specified through the object's properties (see below). The NavigateTo() method, on the other hand, can handle three parameters (cTarget, cLocation and cFrame). The meaning of those parameters is identical to the meaning of the properties of the same name (see below). If those parameters aren't passed, the method uses the property values instead.

Just like the regular Hyperlink base class, the Hyperlink object has GoBack() and GoForward() methods. Again, the Hyperlink object manages this behavior itself, rather than using the native Hyperlink behavior. In fact, the Hyperlink object makes these methods much more useful, because one can navigate multiple times in the same instance of the Web browser. This allows the user to build up a navigation history that can be used to go backward and forward. Using the regular Hyperlink base class, these methods don't make a lot of sense unless the object is used in an active document there won't be a navigation history because a new browser instance is fired up on every navigation.

The Hyperlink object has several properties that allow you to influence how and where the object navigates, and it also has a property that tells the current location (cLocationURL). To initiate a simple navigation, set the cTarget property and fire the Follow() method like so:

oHyperlink = NewObject("_hyperlinkbase","_hyperlink.vcx")
oHyperlink.cTarget = "Http://www.eps-software.com"
oHyperlink.Follow()

You can also set the cLocation property to navigate within a certain URL. A typical example would be a "frequently asked questions" document where you want to navigate to one of the questions rather than to the top of the document. Finally, you can also specify a target frame if you already navigated to a frame-based document. Obviously, this can only work if an existing browser instance is used for navigation. By default, the Hyperlink object tries to find and use such a browser instance. However, you can also specify that you want to open a new window for navigation by setting the lNewWindow property to .T.

Once the navigation is complete, the URL of the current document is stored in the cLocationURL property.

As mentioned above, the Hyperlink object doesn't always use the default navigation behavior of the Hyperlink base class, but it uses Internet Explorer as a COM server instead (if Internet Explorer is the default Web browser). The standard COM server class is "InternetExplorer.Application". This is specified in the cIEClass property. You could use this property to specify a different Web browser class. This might be important if you wanted to use a specific version of Internet Explorer. If the hyperlink object isn't able to instantiate a valid reference of the Internet Explorer COM server, it tries to do a simple shell-execute on the specified target location. This is done using the Shell Execute foundation class. As always, you can specify a different class to be used for shell-executes. You can specify a custom class through the cShellExecuteClass and cShellExecuteClassLibrary properties. More information about the Shell Execute foundation class can be found later in this chapter.

Hyperlink Button

Class

_hyperlinkcommandbutton

Base class

CommandButton

Class library

_hyperlink.vcx

Parent class

_commandbutton

Sample

...\Samples\Vfp98\Solution\Ffc\hyperlnk.scx

Dependencies

_base.vcx

The Hyperlink button is a command button that navigates to a certain URL when clicked. The button adds a bit of Internet look and feel to regular Visual FoxPro forms by using an underlined font and a special color for visited links.

The button has a cTarget property. Use this property to specify the URL to which you want the user to navigate. This is all you have to do to use the Hyperlink button; however, it has more functionality. You can specify (using the cLocation property) a certain bookmark if you want to jump to a specific location within a document. Normally the class looks for a running instance of the Web browser of your choice before it opens a new instance. If you want to open a new instance in any case, you can set the lNewWindow property to .T. If you want to use a specific frame of a loaded document in an existing browser instance, you can use the cFrame property to do so.

When the user clicks the Hyperlink button, the button remembers that the specified URL has already been visited (lVisited = .T.). The caption of the button is then also displayed in a different color. You can specify this color using the nVisitedForeColor property. This property is a numeric RGB value. You can either specify this value directly, or you can use the RGB() method to set the property.

You can even use the Hyperlink Button object to navigate within the URL history using the GoBack() and GoForward() methods. This is especially useful in scenarios where several Hyperlink objects (such as hyperlink buttons, hyperlink images or hyperlink labels) share one behavioral Hyperlink object (the Hyperlink object foundation class). To understand this, you have to know that none of the Hyperlink interface classes have any navigational behavior, but they use the Hyperlink object (see above) instead. By default, all created Hyperlink objects try to share one behavioral Hyperlink object. If you want to use a private Hyperlink object, you can specify this through the lFormSynch property (set it to .F. to create a private Hyperlink object). The Hyperlink button uses the Hyperlink object described above to navigate to the desired location. You can specify a different Hyperlink object by setting the cHyperlinkClass and cHyperlinkClassLibrary properties.

Hyperlink Image

Class

_hyperlinkimage

Base class

Image

Class library

_hyperlink.vcx

Parent class

_image

Sample

...\Samples\Vfp98\Solution\Ffc\hyperlnk.scx

Dependencies

_base.vcx

The Hyperlink Image class is similar to the Hyperlink button. The main difference is that the class is an image rather than a command button. Images don't have forecolors. For this reason, the Hyperlink Image class doesn't allow you to set a special forecolor for visited links. See above (Hyperlink Button) for more information.

Hyperlink Label

Class

_hyperlinklabel

Base class

Label

Class library

_hyperlink.vcx

Parent class

_label

Sample

...\Samples\Vfp98\Solution\Ffc\hyperlnk.scx

Dependencies

_base.vcx

The Hyperlink Label is essentially similar to the Hyperlink Button. As the name suggests, the base class of this class is a label rather than a command button. The Hyperlink Label class transfers Internet look and feel to Visual FoxPro forms since there is virtually no visual difference for the user. Figure 25 shows how the hyperlink label can be used in Visual FoxPro forms. See above (Hyperlink Button) for more information.

Figure 25. Two hyperlink labels used in a regular Visual FoxPro form.

SCX->HTML

Class

_scx2html

Base class

Custom

Class library

_internet.vcx

Parent class

_custom

Sample

None

Dependencies

_base.vcx

The SCX->HTML foundation class is yet another wrapper for Genhtml.prg, just like the
DBF->HTML and the FRX->HTML foundation classes. The only difference is the source, which now is a Visual FoxPro form (SCX) that is converted to HTML format. However, it seems that at this point the possibilities are very limited. I haven't found many forms that have converted to HTML format in an acceptable manner.

See above (DBF->HTML) for more details.

URL Combo

Class

_urlcombobox

Base class

Combobox

Class library

_internet.vcx

Parent class

_combobox

Sample

...\Samples\Vfp98\Solution\Ffc\hyperlnk.scx

Dependencies

_base.vcx, _hyperlink.vcx

The URL Combo foundation class comes in handy when you want to allow the user to navigate to a certain URL by specifying the address manually. The combobox remembers previously accessed URLs and displays them in a drop-down list. Internally, those items are stored in a DBF called Urlhstry.dbf. (You can specify a different table using the cURLHistoryTable property). If you don't want to keep a history, you can set the lURLHistory property to .F.

The URL Combo class is easy to use. You just drop it on a form, drop a button (or another control) right next to it, and call the Navigate() method of the combobox (without any parameters) in the button's Click() event. The combobox then navigates to the URL specified by the user.

To navigate, the combobox uses the Hyperlink object (see above). The Hyperlink object class is specified in the cHyperlinkClass and cHyperlinkClassLibrary properties. You can use these properties to specify your own hyperlink class if you want.

The URL Combo is essentially the same kind of object as the Address combobox of Internet Explorer. However, Internet Explorer's combobox has a nice feature that the URL Combo lacks. It automatically completes the URL as you type when it remembers one. The letters that are filled in automatically are selected immediately, so the user can continue to type if the filled-in URL is not the desired one. Luckily, it is not hard to create the same kind of behavior in a subclass of the URL Combo. You only have to add some code to the InteractiveChange() event. Here it is:

DoDefault()

LOCAL lnLength, lnCounter, lcValue

lcValue = Lower(Alltrim(THIS.Text))

lnLength = Len(lcValue)

FOR lnCounter = 1 TO THIS.ListCount

IF Lower(THIS.List(lnCounter)) = lcValue

THIS.DisplayValue = THIS.List(lnCounter)

THIS.SelStart = lnLength

THIS.SelLength = Len(THIS.List(lnCounter))-lnLength

EXIT

ENDIF

ENDFOR

The code actually is rather trivial. When the user changes the value of the combobox, this code iterates through the items and compares them to the current value. If they are identical (up to the length of the new value), the item is used as the current item and the inserted text is automatically selected. If the user continues to type, the selection is automatically replaced by the new characters (which is Windows-standard behavior) and the whole process starts over.

URL Open Dialog Box

Class

_openaddressdialog

Base class

Form

Class library

_internet.vcx

Parent class

_dialog

Sample

...\Samples\Vfp98\Solution\Ffc\hyperlnk.scx

Dependencies

_base.vcx, _dialogs.vcx, dialogs.h, _hyperlink.vcx

The URL Open Dialog Box is a nice interface class that allows the user to open a Web address (see Figure 26). It is basically the same dialog that Internet Explorer provides when the user selects the File/Open menu item. The dialog basically uses a URL Combo to allow navigation, and it also has a Browse button that brings up a regular GetFile() dialog.

Figure 26. The URL Open Dialog Box.

Using the class is simple just instantiate it and make it visible. The class has only three properties you can set. One of them is cTarget, which stores the URL to which the user tries to navigate. Knowing this might be essential if you want to subclass this dialog. The property lShellExecute specifies whether the dialog should actually initialize navigation. Setting this property to .F. is useful if you want to navigate yourself. I do this frequently when I use the Web browser ActiveX control inside Visual FoxPro. In this case I don't want this dialog to open another instance of Internet Explorer, but I still like to use the dialog.

Finally, the cFileExt property allows you to specify the file types that the GetFile() dialog should display. You can specify multiple values separated by a semicolon (;).

The class also can handle two parameters, which can be used to decorate the lShellExecute and the cFileExt properties. The first parameter can be used to specify that the class should not execute the navigation. In this case you are supposed to pass a .T., which sets the lShellExecute property to .F. This confuses me every time, but it is logical if you consider that Visual FoxPro uses .F. as a default for parameters that haven't been passed. The second parameter is directly assigned to the cFileExt property.

Web Browser Control

Class

_webbrowser4

Base class

OLEControl

Class library

webview.vcx (.\Gallery\_webview.vcx)

Parent class

OLEControl

Sample

...\Samples\Vfp98\Solution\Ffc\webvwr.scx

Dependencies

Microsoft Web Browser ActiveX Control

The Web Browser Control Foundation Class is a wrapper for the Microsoft Web Browser Control (Internet Explorer control). You can use it to build your own Web browsers and to incorporate HTML functionality into your Windows applications (see Figure 27).

Figure 27. Microsoft Expedia Maps incorporated into a regular Windows application using the Web Browser control.

This class has a number of properties and methods, most of which are intuitive and self-explanatory. A great number of methods have been created to handle older versions of this control, such as Internet Explorer 3.0. At this point, this class can handle Internet Explorer versions 3.0 to 5.0.



Advanced Object Oriented Programming with Visual FoxPro 6. 0
Advanced Object Oriented Programming with Visual FoxPro 6.0
ISBN: 0965509389
EAN: 2147483647
Year: 1998
Pages: 113
Authors: Markus Egger

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net