Many of the classes in the MyFrame framework rely on the services presented in this chapter.
Like many developers, I like to instantiate frequently used objects at the beginning of an application, thereby reducing the time consumed on each request.
One way to make an object available is to use a public variable. For example, I would have instantiated the class MyMessages as follows:
166 Build Your Own Framework with Visual FoxPro
RELEASE goMessages PUBLIC goMessages
goMessages = CREATEOBJECT("MyMessages")
However, with the addition of IntelliSense, I now prefer using
_SCREEN.ADDOBJECT(). To understand why, type the following in the command window:
goTextBox = CREATEOBJECT("TextBox") _SCREEN.ADDOBJECT("goTextBox","textbox") MODIFY COMMAND EraseMe
Try typing “goTextBox.” in EraseMe.prg and you will see that IntelliSense is not
available. However, typing “_Screen.g” does activate IntelliSense as shown in Figure 12. One additional benefit is that the _Screen object has only one method or property beginning with the letter G, making it easy to find objects that start with that letter.
Figure 12. Referencing an object added to _SCREEN.
Instantiating framework services
Framework services are instantiated as part of starting the application and released as part of the application close. In Chapter 5, “Beginning Development,” the code for loading and releasing framework components was not completed. The following code has been added to aApplication.
Chapter 11: Framework Services 167
PROTECTED FUNCTION OnLoadComponents() THIS.ReleaseObjects()
_SCREEN.ADDOBJECT("goMessages","MyMessages") _SCREEN.ADDOBJECT("goPreferences","MyPreferences")
_SCREEN.ADDOBJECT("goFormsCollection","MyFormsCollection") ENDFUNC
Notice the call to ReleaseObjects(). This prevents classes from being added to the screen when Main.prg is run more than once. Here’s the ReleaseObjects() code.
PROTECTED FUNCTION ReleaseObjects()
IF PemStatus(_SCREEN,"goMessages",5) _SCREEN.gomessages=.NULL.
ENDIF
IF PemStatus(_SCREEN,"goPreferences",5) _SCREEN.gopreferences=.NULL.
ENDIF
IF PemStatus(_SCREEN,"goFormsCollection",5) _SCREEN.goFormsCollection=.NULL.
ENDIF ENDFUNC
Summary
In this chapter, I illustrated how the Business Object class created in Chapter 10, “Business Objects,” can be extended to provide framework services available throughout the framework and applications created with your framework.
The framework services created in this chapter include a number of features you are likely to require in your framework. They include messaging services, application variables
management, maintaining system codes, remembering object locations, and tracking user preferences.
Having read this chapter, you should have a better understanding of what framework services are and some ideas for how you can incorporate them into your own framework.
Updates and corrections to this chapter can be found on Hentzenwerke’s Web site, www.hentzenwerke.com. Click “Catalog” and navigate to the page for this book.
168 Build Your Own Framework with Visual FoxPro
Chapter 12: Forms 169
Chapter 12 Forms
Complicated business logic and pretty reports have little impact on users that work with your systems. To some users, the forms are the application. The application developer is responsible for making the forms aesthetically pleasing. You are responsible for making them functional. This chapter shows you how.
Forms represent a significant portion of the user interface in many applications. Accordingly, developers expect full control over the behavior of the form and require plenty of hooks to extend the functionality you provide. This chapter reviews several different types of forms, beginning with the framework splash screen.
Splash screens add a professional touch to the start of your applications and distract users from the length of time it takes to load the application. Typically, splash screens display information about the application, such as the name of the application or a logo. You can also use the splash screen to inform the user about the progress of the application startup. In this chapter I’ll explain how to create a splash screen and incorporate it into your startup routine.
Next, I’ll add functionality to the framework form class, aForm, which serves as the parent class for all forms in the framework. Common functionality implemented at this level involves positioning the form properly, resizing controls on the form, and defining a strategy for communicating with toolbars and other forms.
The last topic of this chapter is modal forms, which prevent users from interacting with any other part of the application while the form is active. One of the most common uses of modal forms is to “freeze” an application to collect information from the user and return it to the calling program. In this chapter you’ll see some issues you may encounter when
developing modal forms for your application, and also some examples of the many ways you can take advantage of FoxPro’s modal forms.
Splash screens: MySplash.scx
A splash screen displays information about the application while the application loads. It is common to suppress the title bar, accentuating the contents of the splash screen. Figure 1 shows an example of a splash screen.
FoxPro does not provide a special “splash screen” form. Any form can appear as a splash screen if you change a few properties. The following settings will make a form appear as a splash screen:
170 Build Your Own Framework with Visual FoxPro
Figure 1. A sample splash screen.
Design considerations
A splash screen is the first thing a user sees when starting an application. The application developer will want the splash screen to appear in front of the user as quickly as possible to provide immediate feedback that the application is starting. Showing the splash screen before checking machine capacities, loading class libraries, and performing the host of other actions that occur during the start of an application is the fastest way to get the screen in front of the user. You should base the splash screen directly on the FoxPro base controls—rather than on your framework base classes—so you can run the splash screen before loading your class libraries.
The application developer may want to display information about the progress of the application while it is starting. Aside from being informative, visual changes in the screen assure users that the application is not “stuck,” because they can see the form is changing.
Displaying information about the application startup has an additional benefit. If the application experiences problems while loading, the step in progress will be displayed on the screen, making it easier for the user to identify at which point the problem occurred.
MySplash.scx
The splash screen included as part of MyFrame is MySplash.scx. You will find it in the .\Meta folder. A copy of MySplash.scx is placed in the .\appsource\ folder at the start of each new project. MySplash.scx is shown in Figure 2.
As you can see in Figure 2, MySplash does not have a title set or a picture defined. These are left for the application developer to fill in.
To enable the splash screen to open before you issue any SET CLASSLIB commands, MySplash.scx and the controls it contains are based directly on the FoxPro base classes, rather than the framework classes in MyFrame. Additionally, some functionality has been added to MySplash. Here are the relevant properties and events:
• SetStatus(): This method accepts one character parameter and displays its value in the lower portion of the screen.
• Init(): Optionally accepts a title to display in lblTitle.
• lblTitle: A center-aligned label. To set the title you can either set the caption directly or pass it as a parameter when creating the form.
Chapter 12: Forms 171
• Timer1: Releases the splash screen after a period of time has elapsed. The default is 15 seconds.
• AutoCenter: Is set to .T.
Figure 2. The splash screen for MyFrame.