Thursday, February 17, 2011

Converting Your Existing Applications to Visual FoxPro 3.0

Converting Your Existing Applications to Visual FoxPro 3.0


--------------------------------------------------------------------------------

Joe Homnick

Homnick Systems.

Introduction

Visual FoxPro 3.0 has opened up a wealth of new developer tools that can only be considered as revolutionary for the FoxPro programmer. From object orientation to visual form and class tools, the whole application scheme has been revamped. Even though Visual FoxPro’s new environment provides a whole new way of doing things, your existing FoxPro 2.6 application can be almost seamlessly integrated into this brave new developer environment. The expansiveness of the new FoxPro features can be daunting, but this is mitigated by the conversion utilities built into VFP. This paper will look at how you go about converting your existing 2.6 application in Visual FoxPro. With this conversion you can start using these wonderful new features while still leveraging your existing development investment.

Successful conversion of an application requires planning of how the components of the application will be converted. The decision process is two fold. First, it must be decided if you want to take the default Functional conversion, that completely converts the 2.6 screen to a backwardly compatible Visual FoxPro form set, or Visually converting the form, which entails running the 2.6 coded SPR and manually implementing the converted form set. Secondly, decisions have be made on how you wish to incorporate the new extensions found in Visual FoxPro. The second question directly affects the first of Visually or Functionally converting your screens. However, no matter what conversion route you choose, the conversion will run your existing application AS IS, in the new Visual FoxPro environment.

The areas affected by conversion include projects, forms, reports, labels and code. The most intensive area is what used to be known as screens in FoxPro 2.6 and are now known as forms in Visual FoxPro. However, we will take a top down approach by looking at converting a project first and then working our way through the other components.

Converting Projects:

Conversion of a project from 2.6 to Visual FoxPro starts by opening the 2.6 project in Visual FoxPro. Visual FoxPro will recognize the file is a 2.6 PJX file and process it through the convert.app application. This convert.app application is installed by default in the Visual FoxPro home directory. Upon starting the conversion utility, a dialog, as depicted below, is presented to the developer.


This conversion dialog is very much like the dialog that is presented to you when you open a non converted 2.6 SCX screen file.

The first option of the dialog relates to if and where back up copies of pre-converted 2.6 screen sets are copied to. Before converting the 2.6 screen to a Visual FoxPro form, convert.app will create a directory OLD, off of the designated one.

The second option allows the specification of a log file. This is a text file with the suffix .LOG and contains a recap of the conversion process. The information includes, if conversion took place, elapsed time of the conversion, whether the conversion was successful or not, and error messages related to unsuccessful conversion. If problems occur during conversion, this log will be the source of detail for those errors.

Selecting Functional or Visual conversion is the area of most concern for the developer in converting their applications. Both conversion methods allow you to simply convert your application, build it and the run the resulting APP or EXE, the differences between the methods come into play when you start implementing and extending the converted form.

The Functional conversion creates the most hands off type of conversion, but can cause more work when extending your existing application with the new features built into Visual FoxPro. With Visual conversion, the forms in the application are better prepared to take advantage of Visual FoxPro’s new features, but require manual placement of the code behind the forms. The project implements these two methods in two very distinct ways. We’ll first look at the differences in the conversion methods as they relate to the project and then follow up with a detailed look at how forms are converted differently under the two methods.

When Functional conversion takes place, the forms are converted and the converted forms are called within the application. Under Visual FoxPro the code to call a form is DO FORM , in FoxPro 2.6 the syntax is DO .SPR. The converter does not modify the original calls to the forms, but creates a corresponding SPR file that executes a DO FORM . Here’s what the customer.spr program looks like after Functional conversion takes place, this would be executed with a DO CUSTOMER.SPR:

*- CUSTOMER.SPR
*- [CONVERTER] Declare variables for record pointers
PUBLIC _iconvCustomerGoToPlaceHolder

DO FORM "CUSTOMER.SCX" NAME _R2716LSBP LINKED

*- [CONVERTER] Begin CLEANUP and other procedures from 2.x Form

PROC CLEANUPSAMP
WAIT WIND 'nada'

*- [CONVERTER] End CLEANUP and other procedures from 2.x Form

Note that a public variable is initialized. This variable is filled with the current record number during the unload event of the form, to be used to reset the record pointer when reentering the form. Additionally, any procedures or functions that existed in the 2.6 clean up code are placed into this SPR. Unlike a standard Visual FoxPro form, this form emulates a 2.6 read and creates a wait state while the form is running. The program does not finish executing until after the form is released, thereby giving the form access to procedures and functions contained within the calling SPR program.

A Visual conversion differs in that although the screen is converted, the SPR is not overwritten with the code demonstrated above. The SPR remains the same as it was in 2.6 and is simply recompiled. The converter doesn’t make assumptions about where to place code snippets in the new Visual FoxPro form set, but rather writes them out to a program file. The new Visual FoxPro form will not run if it is dependent on these disembodied snippets. To make the form functional, there needs to be some interaction by the developer. First in calling the form with a DO FORM and placing the code snippets in their correct events of the form.

Converting from the project level is the most desirable way to convert an application. Not only does it convert all components of an application, it is the only method that will convert multiple screen sets into a Visual FoxPro form set.

Form Conversion

Form conversion can be invoked by opening a 2.6 screen or electing to convert a project that contains screens. Either method presents the developer with the election of executing the default Functional or optional Visual conversion. The resulting forms from each conversion method differ in several ways. The resulting forms from a Functional conversion result in a complete working form that respects all facets of the previous 2.6 environment. The Visually converted forms require the developer to manually place code snippets where appropriate.

Functional Form Conversion

Functional conversion creates a form set and places all the controls from the 2.6 screen onto a Visual FoxPro form within a page frame container. Each page frame relates to an individual read in the predecessor 2.6 screen, so if the screen was created in 2.6 with multiple reads they would each correspond to a page frame in the converted Visual FoxPro form. Even though multiple reads in a single screen were not a common implementation method in 2.6, the Functional conversion takes their possible implementation into consideration and can be considered one of the major draw backs of this method.

The most important setting in the Functionally converted form is the form set WindowType property. If the value of this property is 2 or 3 then the form set takes on the read qualities of a 2.6 screen set. Execution stops when a DO FORM or SHOW command calls the form. The WindowType value of 2 is a normal form set which can be deactivated, a value of 3 makes the form modal so that it must be released before execution can start again. This WindowType properties relating to 2.6 screen compatibility are only available with Functionally converted 2.6 screens. When screens are converted Visually or are created in Visual FoxPro, this WindowType property only relates to standard Visual FoxPro modeless and modal behavior and does not allow the backwardly compatible settings of 2 and 3. The only time you will see form set WindowType properties with READ capabilities is in a Functionally converted form set.

Code is moved from the 2.6 events to Visual FoxPro events in a specific pattern. The following is a table of the conversion of 2.6 events to Visual FoxPro events.

FoxPro 2.6 Screen Event Converted Visual FoxPro 3.0 Event
Setup - #Section 1 FormSet.Load
Setup - #Section 2 Form.Load
Activate Form.Activate & FomSet.Activate
Deactivate FormSet.Deactivate
Show FormSet.ReadShow
When FormSet.ReadWhen
Valid FormSet.ReadValid
Cleanup FormSet.Unload & SPR for procs/functions

The READ key words CYCLE, LOCK, MOUSE, SAVE, and TIMEOUT are moved to form set properties with the names ReadCycle, ReadLock, ReadMouse, ReadSave, and ReadTimeout.

Abehavior unique to this backwardly compatible screen relate to variable scoping. Variables that are defined in the load event are scoped to the life of the form. This is for backward reasons only and does not conform with standard Visual FoxPro variable scoping

It should be noted that there are environmental settings are automatically defined in the FormSet.Load event and the current record pointers are saved in public variables during the FormSet.Unload event. The Data Environment of the form is updated with all appropriate 2.6 View Environment objects such as the table alias’s, index orders, relationships. The 2.6 generator directives for automatically opening and closing the tables are moved to the properties AutoOpenTables and AutoCloseTables in the DataEnvironment object.

Extending a Functionally-Converted Form

The following is a twelve step program for extending functionally converted forms into a Visual FoxPro format. By definition, the functional conversion creates a backwardly compatible form set. By applying these twelve steps to the situations that apply to the particular form, you can change the backwardly compatible form set into a standard Visual FoxPro form set. This conversion process is an excellent learning tool for the 2.6 programmer moving to Visual FoxPro.

Move parameter code from load event to init event


Change form level variables to user defined form properties


Create form methods for form specific procedures and functions (those moved to the SPR)


Change CLEAR READ to RELEASE ThisFormSet or RELEASE ThisForm


Change SHOW GET to .Refresh


Change SHOW GETS to ThisForm.Refresh or ThisFormset.Refresh


Change SHOW GET for List and Combo boxes to .Requery


READSHOW, READWHEN, should be moved to the Formset Load event


READACTIVATE, READDEACTIVATE, should be moved to the Formset Activate and Deactivate events


READVALID should be moved to the QueryUnload event


Foundation reads should be converted to READ EVENTS and CLEAR EVENTS


Change the WindowType property to 0 or 1
Visual Form Conversion

Visual conversion approaches form conversion in a Visual FoxPro related paradigm, as opposed to the backwardly compatible one in Functional conversion. The resulting form set and forms mimic a standard Visual FoxPro form set arrangement, while the Functional conversion mimics 2.6 behavior. There are no page frame containers in the Visually converted form and the form set WindowType property is set to 0 for modeless or 1 for modal. Unlike the Functionally converted form, execution does not stop when the form is called with a DO FORM or SHOW command.

The most significant difference between the two conversion methods, at least as it relates to developer interaction, is that Visual conversion does not place any code snippets into form events. When conversion takes place the code snippets are separated into a PRG file so they can be implemented visually by the developer into the converted form. An example of this PRG file shows a converted 2.6 push button valid snippet that calls a search screen.

*----------------------------------------------
*- Code from C:\jfhapp\screens\JCONT1.SCX
*----------------------------------------------

*----- cmgOption1
PROCEDURE Valid
DO search.spr
ENDPROC

After code is placed from the conversion PRG into the form, the developer needs to integrate the form into the application. To implement the converted form into a project, the call to the screen needs to be changed from DO .SPR to DO FORM or the SPR needs to be changed to explicitly call the form with a DO FORM command. Remember that miscellaneous procedures/functions from the 2.6 screen cannot be put into the SPR since launching the form does not stop execution under standard Visual FoxPro behavior. These items need to be added to a PROCEDURE file or implemented within the form as methods. Note that if procedures are implemented as form methods, the calls to the procedures must change also.
Deciding Between Visual or Functional Conversion

When executed through the project manager, both Visual and Functional form conversion end up with a FoxPro 2.6 application running in Visual FoxPro 3.0. The difference is that with Functional conversion, the forms that run in the application, are the actual converted forms. With Visual conversion, the original 2.6 SPR is running in the application. Since the initial result is the same, the question of which method to select comes down to how extensive the maintenance to forms is expected in the future. If expected future maintenance can be expected to be minor and cosmetic in nature, then Functional conversion would be a logical choice. If larger scale changes to the forms can be foreseen, then the developer might opt for a Visual conversion that will allow a complete implementation of the new Visual FoxPro model. A very important point to remember is that the Visually converted form do not contain the page frame controls that the Functionally converted one does.

Through project conversion you cannot selectively convert some screens Visually and others Functionally. Project conversion is an all or nothing proposition. This can be somewhat mitigated by being able to selectively convert forms, after the fact, from the backup OLD directory. Of course, screen set properties, such as multiple screens, are only available through the project manager. If a hybrid method of converting forms is required, consideration of doing two separate project conversions and mixing/matching the results should be considered.

No matter which method is selected. It should be noted that the extension of a Functionally converted form to a Visual FoxPro format is an excellent learning tool and should be investigated if only for that reason.

What Can Cause Conversion Problems

Be careful with macro substitution in properties. For example a 2.6 push button prompt of &buttonprompt will be converted to =”&buttonprompt” in the Visual FoxPro caption property of the converted command button. This needs to be changed to =buttonprompt in the property sheet.

It is possible to have a conflict in the Visual FoxPro naming convention by having a long variable name with 10 common characters, not very likely, but a definite gotcha.

There are new reserved words in Visual FoxPro, if you run into an unexplainable problem with certain code, check it against the reserved word list found in the help file.

Overlaying of controls is handled differently. If the resulting appearance is not as desired, consider reordering the objects and implementing the Zorder method.

Reports and Labels

The only significant modifications to 2.6 FRX and LBX files are the addition of additional rows to contain information related to the Data Environment object.. If the report/label was saved with an environment in 2.6 the AutoOpenTables and AutoCloseTables in the DataEnvironment object are set to .T. and table alias’s, index orders, relationships objects are added to the Data Environment.

Extending Existing Code

The grid control has taken over as an objectified browse, so that future browse type implementations will be grid based. However, your existing browse code can be objectified through the use of the NAME keyword. You can define the browse NAME object and then manipulate the browse in a PEM (Property, Event, Method) Visual FoxPro fashion. Here is an example of objectifying a browse using the name property and then changing the BackColor property of the objectified browse to turn the background color of the browse red.

USE customer
BROWSE NAME oBrowseGrid
oBrowseGrid.BackColor=RGB(255,0,0)

This new named object can be manipulated just like a grid object. Your existing browses can easily be extended to include dynamic colors, combo box or spinner column controls, etc. All capabilities of the new grid control can be added to your existing browse, with very little coding.
This same NAME keyword is available for all the @...GET commands so existing code for the objects on forms can be objectified just like the browse command.

dBASE and FoxPro for MS-DOS

The conversion utilities work the same with Dbase forms and reports. If you are converting from a FoxPro platform that would require conversion to FoxPro for Windows, such as FoxPro DOS, the FoxPro for Windows transport utility will first transport to windows objects and then convert to Visual FoxPro.

Conclusion

The conversion capabilities built into Visual FoxPro allow the 2.6 developer to easily move their existing application into the new visual and object oriented Visual FoxPro development environment. Whether the conversion is functional or visual, the existing 2.6 application will run virtually untouched in Visual FoxPro. Using the visual tools, class libraries and code extensions, the developer can learn how to add Visual FoxPro functionality to their already running application. Thereby, learning this brave new world while still leveraging their existing investment.

1 comment:

  1. software development company india
    I was suggested this blog through my cousin. I’m now not certain whether or not this post is written by him as no one else recognize such precise approximately my trouble. You’re incredible! Thanks!

    ReplyDelete