OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Creating Template Class Instances

Once you have defined a template class, you can create any number of instances of that class.

You can use template class instances to provide different descriptions of a template, search for different default file names, look in different default directories, and so on. You can affect all these things when calling the template class constructor.

The signature of a template class constructor is always the same:

TplName name(TRegList& regTable);
ElementDescription
TplNameThe class name you specified when defining the template class
nameWhatever name you want to give this instance
regTableThe name of a registration table created using the BEGIN/END_REGISTRATION macros (see Creating Document Registration Tables)

Example

For example, suppose you have the following template class definition:

DEFINE_DOC_TEMPLATE_CLASS(TPlotDocument, TPlotView, TPlotTemplate);
#define DEFINE_DOC_TEMPLATE_CLASS(docClass, viewClass, cls)
Definition doctpl.h:431

Now suppose you want to create three instances of this template class:

  • One instance should have the description "Approved plots" for document files with the extension .PLT. Allow only a single view of the document and automatically delete the document when the view is closed.
  • Another instance should have the description "In progress" for document files with the extension .PLT. Automatically delete the document when the last view is closed.
  • Another instance should have the description "Proposals" for document files with the extensions .PLT or .TMP, but with the default extension of .PLT. Keep this template hidden until the user has entered a password and delete the document object when the last view is closed.

The code for these instances would look something like this:

REGDATA(description, "Approved plots")
REGDATA(docfilter, "*.PLT")
REGDATA(extension, "PLT")
REGDOCFLAGS(dtSingleView | dtAutoDelete)
TPlotTemplate atpl(aReg);
REGDATA(description, "In progress")
REGDATA(docfilter,"*.PLT")
REGDATA(extension, "PLT")
REGDOCFLAGS(dtAutoDelete)
TPlotTemplate btpl(bReg);
REGDATA(description, "Proposals")
REGDATA(docfilter, "*.PLT; *.TMP")
REGDATA(extension, "PLT")
REGDOCFLAGS(dtHidden | dtAutoDelete)
TPlotTemplate *ctpl = new TPlotTemplate(cReg);
#define REGDATA(var, val)
Definition registry.h:591
#define REGDOCFLAGS(i)
Definition registry.h:598
#define BEGIN_REGISTRATION(regname)
Definition registry.h:583
#define END_REGISTRATION
Definition registry.h:589

Note that, as with any other class, you can create both static and dynamic instances of a document template.

See Also