• No results found

The proxy class in MyFrame

In document Framework eBook (Page 61-64)

A proxy is a placeholder for another object. The class MyProxy has a LoadProxy() method that is responsible for carrying out the tasks associated with a proxy. They are:

• Add a new object to the parent container.

• Resize the object to occupy the same space as the proxy.

• Make the object visible.

Two properties have been added to MyProxy: cClassToLoad and cNewClassName. To use this class, enter the class name you want to create in the cClassToLoad property and the name you want to assign to the class in the cNewClassName property.

The code for LoadProxy() is shown here:

*--MyProxy.LoadProxy()

LOCAL lcNewClass, loParent AS FORM, lcNewObjectName

lcNewClass = ALLTRIM(THIS.cClassToLoad) lcNewObjectName = ALLTRIM(THIS.cNewClassName)

IF ! EMPTY(lcNewClass) AND;

! EMPTY(lcNewObjectName) AND;

! THIS.lLoaded AND;

TYPE("THIS.PARENT") = 'O' WITH THIS.PARENT

*--Add The Object

.ADDOBJECT(lcNewObjectName,lcNewClass) *--Set the position

.&lcNewObjectName..TOP = THIS.TOP .&lcNewObjectName..HEIGHT = THIS.HEIGHT .&lcNewObjectName..WIDTH = THIS.WIDTH .&lcNewObjectName..LEFT = THIS.LEFT *--View it

.&lcNewObjectName..VISIBLE = .T.

Chapter 4: Techniques for Flexibility 39

*--Prevent it from loading again THIS.lLoaded = .T.

ENDWITH ENDIF

Label vs. custom classes

End users never see proxies. Their very purpose is to load some other class that users do want to see. Classes that are purely functional and that require no visual representation seem perfect candidates for the custom class. However, MyProxy is a subclass of aUtilityLbl, which is a label.

At various points in the MyFrame framework, I choose to use labels rather than the custom class. Labels allow me to convey extra information about the class at design time. In Figure 1, the label is the proxy. The custom class is added to show what the proxy would look like if it were based on the custom class.

When I wear my framework developer hat, I use the caption to convey information about how to use the class. As you can see in Figure 1, the caption for MyProxy explains how to use the class. When I’m wearing my application developer hat, I might place comments in the caption about why I chose to use a proxy.

Figure 1. The Proxy demonstration form, TestProxy.scx.

To use the proxy, drop the class on a container object (form, page, and so on) and resize it as desired. Enter the name of the class you want to load in cClassToLoad and the resulting name of the class in cNewClassName. TestProxy.scx is included in the samples for this chapter.

Wrappers

The intent of a wrapper class is to change the interface of a class. Typically this is done to provide uniformity when working with various classes. Consider the delegate example presented earlier. In the example, each delegate is required to have a ShowMessage() method accepting one parameter. A wrapper class could be used to morph existing classes so they meet the interface requirements of SampleForm.

40 Build Your Own Framework with Visual FoxPro

Summary

In this chapter, you have learned several techniques to incorporate flexibility into your

framework. These techniques are used in various places throughout MyFrame, giving plenty of examples of how these concepts can be applied in practice.

Armed with the examples provided in the chapter and the examples of how they are applied in practice, you should be in a better position to understand how flexibility is incorporated into commercial frameworks and how to use these techniques in your work.

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.

Chapter 5: Beginning Development 41

Chapter 5 Beginning Development

The success of your framework depends upon the ability of the application developer to create fully functioning applications. Focus on quality and productivity. Ultimately those are the criteria on which your framework will be judged.

The first time I began developing a framework, it was exciting thinking of all the features I was going to include: a splash screen, business logic, resizable forms, and so on. I made coffee, sat in front of my computer, and then it really hit me: This is a huge project. Where do I start?

Like any computer project, a FoxPro project is a collection of files. The development of the MyFrame framework begins with an explanation of the framework folder structure and how to organize files to accommodate multiple projects. The next step is to create some of the framework files. In this chapter, I introduce procedure files: a header file, a configuration file, the framework class library, and the framework database. Throughout the book, the contents of these files are extended, much as you would do as you develop your own framework. If you have pre-existing procedure or class libraries, this is a good time to incorporate them into your new framework as well.

The last section in this chapter introduces an application object and the main program responsible for loading and unloading the framework files. In this early stage of development, the application object is merely an application shell responsible for all the events surrounding the beginning and end of an application. We will be adding functionality to our application object as we progress through the book.

In document Framework eBook (Page 61-64)