Condividi tramite


The Subclassing of Objects

You can create custom objects by subclassing the base classes provided with Visual FoxPro. For example, the following code subclasses the Outline control provided with Visual FoxPro:

Subclassing the Outline Control

Code Comments
PUBLIC frmMyForm, cFilename
SET SAFETY OFF
Declare variables and initialize.
frmMyForm = CREATEOBJECT("form")
frmMyForm.Width = 100
frmMyForm.ADDOBJECT("oleOutl","myoutline")
DIMENSION aSection(3)
aSection(1) = "Table"
aSection(2) = "Field"
aSection(3) = "Index"
Create a form, add the custom outline control to the form, and then create an array for the items that the control lists.
cFilename = GETFILE("dbc","Select a DBC")
USE (cFilename)
INDEX ON objecttype FOR (objecttype = "Table" ;
   OR objecttype = "Field" ;
   OR objecttype = "Index" ) ;
   TAG fname
Prompt for a database that contains the information you want the control to list.
FOR nIndex = 1 TO 3 STEP 1
   frmMyForm.oleOutl.AddItem(aSection(nIndex))
   frmMyForm.oleOutl.Indent;
    ((frmMyForm.oleOutl.ListCount-1)) = 1
   SCAN
      IF objecttype = aSection(nIndex)
         frmMyForm.oleOutl.Additem(objectname)
         frmMyForm.oleOutl.Indent;
         ((frmMyForm.oleOutl.ListCount-1)) = 2
      ENDIF
   ENDSCAN
   GO TOP
ENDFOR
Gather information from the database, and then add it to the control.
frmMyForm.oleOutl.Visible = .T.
frmMyForm.Show
Make the control visible, and then display the form.
DEFINE CLASS myoutline AS olecontrol
   OleClass = "msoutl.outline"
   Top = 5
   Left = 5
   Height = 10
   Width = 60
ENDDEFINE
Define a subclass of the OLE Container control and add the outline control by setting the OleClass property of the container, and then defining other custom settings.

If you want to distribute your applications, there are some additional considerations.

See Also

Manipulation of Objects with Automation | The Control of Visual FoxPro from Other Applications | Adding OLE | Using Remote Automation | Using ActiveX Controls