Working with SubForms in dBASE

Last Modified: July, 2002
Ken Mayer, Senior SQA Engineer
dBASE Inc.


Example code can be obtained here: SubformSamples.zip


What Is a SubForm?
What exactly is a subform? Simply put, it is a form contained within another form. It is a new type of container that can be used in your forms, and it acts mostly like a regular dBASE form (see details given below).

In terms of dBASE's dBL programming language, a subform is a new object in dBASE Plus, subclassed (internally) from the stock form class.

For all intents and purposes, a subform has all the properties, methods and events of a standard form, except as noted below -- the following information is from dBASE R&D:


How Do I Use a SubForm?
Programmatically it's as simple as:

fMain = new Form()
fSub = new SubForm( fMain ) // 'fMain' here is the PARENT form
fMain.open()
fSub.open()

The code shown above would produce the following:


Form with a subform

Note that there is an optional parameter after the parent reference. The optional parameter is the text that appears in the titlebar of the subform. You can either set this when you create an instance of the subform or you can set the subform's text property.

fMain = new Form()
fSub = new SubForm( fMain, "My Subform" )
        // 'fMain' here is the PARENT form
        // and the text "My Subform" is the titlebar text

fMain.open()
fSub.open()

As a developer there are a few things that are useful to know:

You can use a form's OPEN method, or ONOPEN event to open subforms, you can use pushbutton onClick events -- you have a lot of power and flexibility here.


Using the Designers to Create Subforms
The form designer does not, at this time, directly support the creation or modification of subforms. However, if you create a form, you can make it a subform by changing the following statement:

class TestFormForm of FORM
    // Change to:
class TestFormForm( oParent, cTitle ) of SUBFORM( oParent, cTitle )

Note that when you make this change, the subform cannot be modified in the form designer unless you change that statement back.



DISCLAIMER: the author is an employee of dBASE, Inc., but has written this on his own time. If you have questions regarding this .HOW document, or about dBASE you can communicate directly with the author and dBVIPS in the appropriate newsgroups on the internet.

HOW TO files are created as a free service by members of dBVIPS and dBASE, Inc. employees to help users learn to use dBASE more effectively. They are edited by both dBVIPS members and dBASE, Inc. Technical Support (to ensure quality). This HOW TO file MAY NOT BE POSTED ELSEWHERE without the explicit permission of the author, who retains all rights to the document.

Copyright 2002, Kenneth J. Mayer. All rights reserved.


EoHT: SubForms.htm -- July, 2002 -- KJM