Implementing a strategy or strategy implementation is defined as "the translation of strategy into organisational action through organisational structure and design, resource planning and the management of strategic change".
The next component in the implementation stage of the strategy is the management of strategic change. It could also be a change in strategy that will necessitate the change.
Associated with management of strategic change is the problem of change management. Abstract: Visual Class Libraries allow you to build powerful Visual FoxPro applications and to implement powerful Object Oriented features. This article (Part 1) will discuss how to build data aware Visual FoxPro classes for use in your pure Visual FoxPro desktop code. Code contained in a class can be accessible once you create an instance of that class for use in your code.
In , classes are contained in Visual Class Library (.vcx) files or you could even dynamically create one in code using the CREATE CLASS command. You could open the employees table, scan until you find the employee record and then check its status field! Lets imagine that you had the following table called Employee in a Visual FoxPro Database:
CREATE TABLE Employees (EmpID I NOT NULL AUTOINC NEXTVALUE 1 STEPVALUE 1 PRIMARY KEY
The Employees Class
The Employees class will provide the data services required by your application’s form including saving information, deleting data and searching for existing information and then returning these to the form as the need may be.
You can now organize your class based on the following class diagram:
Method
Delete an employee from the table
Method
Search for an Return an Employee Record
Create the Class
- Select the Visual Class Library to which you want to add the new Employees class on the Classes tab and then choose the New button. The New Class dialog box displays.
- Enter Employees on the Class Name box and then select Custom from the Based On drop down list box
- Choose Ok.; The Class Designer displays.
Now that the Class Designer displays, you can proceed to add your properties to your class. You can add properties to your visual class by performing the following action:
Choose the New Property menu command from the Class main menu. In the Name box, type the name of your property. For example, EmpID.
If you set visibility to Hidden, only members of your class will see it.
In the Default/Initial value field, initialize the value of the property. Choose the Add button to add the class.
Repeat this action to add all the properties in your class.
Choose the New Method menu command from the Class main menu. The New Method dialog box displays.
In the Description box, type the description of the class. Choose the Add button to add the method.
In the Visibility box, choose Public. Like properties, methods could either be Public, Hidden or Protected.
Add Code to your methods
Visual FoxPro would give the control the name Employees1.
THISFORM.Employees1.EmpID = THISFORM.txtEmpID.Value
THISFORM.Employees1.EmpName = THISFORM.txtEmpName.Value
THISFORM.Employees1.EmpDept = THISFORM.txtEmpDept.Value
THISFORM.Employees1.EmpStatus = THISFORM.txtEmpStatus.Value
lAnswer = THISFORM.Employees1.Save(“Data Aware Class”)
IF NOT lAnswer
; cMsg = “Record not saved successfully!”
; MESSAGEBOX(cMsg,64,”Data Aware Class”)
; RETURN
ENDIF
THISFORM.cmdNew.Click; Clear form for new/next record
; cMsg = “Enter an employee name!”
; RETURN .F.
; ENDIF
; IF USED(“Employees”)
ENDIF
SELECT Employees
IF THIS.EmpID <= 0
ENDIF
REPLACE Employees.EmpName WITH THIS.EmpName
ENDIF
RETURN .T.
Find and Return a Record
Another critical service that your class would perform would be to search the table for an existing record and then return that record to you. Your Data Form could contain a Find button whose click event could contain the following code:
IF THISFORM.txtEmpID.Value = 0
; MESSAGEBOX(cMsg,64,”Data Aware Classes’)
; RETURN
lAnswer = THISFORM.Employees1.FindEmployee(THISFORM.txtEmpID.value,”Data Aware Classes”)
IF NOT lAnswer
; MESSAGEBOX(cMsg,64,”Data Aware Classes”
; THISFORM.txtEmpID.Value = 0
; THISFORM.txtEmpName.Value = THISFORM.Employees1.EmpName
; THISFORM.txtEmpDept.Value = THISFORM.Employees1.EmpDept
; THISFORM.txtEmpStatus.Value = THISFORM.Employees1.EmpStatus
The code in the FindEmployee method of the class could then look like this:
IF nEmpID = 0; No employee ID supplied…exit
IF USED(“Employees”); If file is already in use…use it
SELECT Employees
LOCATE FOR Employees.EmpID = THIS.EmpID
; IF NOT lFileInUse Close the table
IF NOT lFileInUse Cloise Table if we opened it
Your form could call the class method to perform the deletion by having code such as this:
IF THISFORM.txtEmpID.Value = 0
; cMsg = “Display an existing record and then try again!”; MESSAGEBOX(cMsg,64,”Data Aware Classes”
lAnswer = THISFORM.Employees1.RemEmployee(THISFORM.txtEmpID.Value,”Data Aware Classes”)
IF NOT lAnswer
MESSAGEBOX(cMsg,48,”Data Aware Classes”)
cMsg = “Record was successfully deleted!”
MESSAGEBOX(cMsg,64,”Data Aware Classes”)
The above code calls the Class module with the line lAnswer = THISFORM.Employees1.RemEmployee. Now the RemEmployee class can have the following code:
LOCAL cMsg, lAnswer, lFileInUse
IF nEmpID = 0; No employee record was supplied
IF USED(“Employees”)
SELECT Employees
IF NOT FOUND()
; IF NOT lFileInUse Close the file
IF NOT lFileInUse
In the Code above, the calling procedure passes the employee ID of the record to be removed to the RemEmployee method of the class. The method checks for and opens the table if need be and then uses a LOCATE command to check to see if the record already exists.
Using your class