OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Step 6: Creating helper objects for a document

Each new document you open needs two helper objects from ObjectComponents: TOcDocument and TOcView.

Because you create a client window for each document, the window's constructor is a good place to create the helpers. The TOleWindow::CreateOcView function creates both at once. In OWLOCF2, the client window is TScribbleWindow. Here is the declaration for the class and its constructor:

class TScribbleWindow : public TOleWindow
{
public:
TScribbleWindow(TWindow* parent, TOpenSaveDialog::TData& fileData);
TScribbleWindow(TWindow* parent, TOpenSaveDialog::TData& fileData, TRegLink* link);

The second constructor is new. It is useful when ObjectComponents passes you a pointer to the registration information you provided for one of your document types and asks you to create a document of that type. Here is the implementation of the new constructor:

TScribbleWindow::TScribbleWindow(TWindow* parent, TOpenSaveDialog::TData& fileData, TRegLink* link)
:
TOleWindow(parent, 0), FileData(fileData)
{
.
.
.
// Create a TOcDocument object to hold the OLE parts that we create
// and a TOcRemView to provide OLE services
CreateOcView(link, true, 0);
}

The constructor receives a TRegLink pointer and passes it on to CreateOcView. The pointer points to the document registration information for the type of document being created. ObjectComponents passes the pointer to this constructor; you don't have to keep track of it yourself.

Passing true to CreateOcView causes the function to create a TOcRemView helper instead of a TOcView. The remote view object draws an OLE object within a container's window. When a server is launched to help a client with a linked or embedded object, it should create a remote view. If your application supports more than one document type, you can choose to use a different TOleWindow-derived class for each one. You must then provide the additional constructor for each class. Alternatively, you can use a single TOleWindow-derived class that behaves differently depending on the TRegList pointer it receives.