Click to See Complete Forum and Search --> : Deriving intermediary class from CFormView


William Heitler
October 7th, 1999, 06:37 AM
I have a project which has several FormViews attached to the same document. They all do different things, but share some functionality. I would like to do what I think is the correct OO thing - stuff the shared code into an intermediary class derived from CFormView, and then derive my real FormViews from this class. I tried this by deriving a CBaseView from CFormView using class wizard (using a sparse dialog as a dummy placeholder), and then doing a global replace of CFormView with this derived class in one of my "real" FormViews, but the compiler chokes saying the CBaseView constructor doesn't take 1 parameter. I did a few experiments, but basically, I got into a terrible tangle with the various macros concerning the template, dynamic creation etc. I think the problem lies in passing the real dialog template back to CFormView, but I am not sure. Can anyone tell me a) is it possible to do what I want, and if so, b) what's the syntax?

AZur
October 7th, 1999, 06:46 AM
I use following implementation:

class CmyFormView : public CFormView
{
protected: // create from serialization only
CsdeFormView();
CsdeFormView( UINT nIDTemplate );
DECLARE_DYNCREATE(CsdeFormView)
...
}; // class CmyFormView

IMPLEMENT_DYNCREATE(CmyFormView, CFormView)

CmyFormView::CmyFormView()
: CFormView(UINT_MAX)
{
// ... should be never called
} // construction

CmyFormView::CmyFormView( UINT nIDTemplate )
: CFormView(nIDTemplate)
{
// ... do something
} // construction

William Heitler
October 7th, 1999, 08:47 AM
I'm a bit puzzled by your message on 2 points:

First, in
class CmyFormView : public CFormView
{
protected: // create from serialization only
CsdeFormView();

is the "CsdeFormView" a typo for CmyFormView, or am I missing something crucial?

Second, if I understand it correctly, I think you are deriving directly from CFormView. I have several FormView-derived classes,
and what I want is to make an intermediary class into which I can put some code which is common to all of them
CFormView // provides basic FormView functionality
CIntermediaryFormView // provides some common code (for printing, actually)
CRealFormView1, CRealFormView2, CRealFormView3 // displays on screen as FormView, with access to comon printing code

Best wishes

Bill

AZur
October 7th, 1999, 09:03 AM
At first, sorry Bill, "CsdeFormView" should be "CmyFormView", it's a typo.

At second you are right, use the Wizard if you want and change later "CFormView" to "CmyFormView" in the *.h and *.cpp Files

class CRealFormView1 : public CmyFormView
{
protected:
CRealFormView1(); // protected constructor used by dynamic creation
DECLARE_DYNCREATE(CRealFormView1)

// Form Data
public:
~CRealFormView1(); // destructor

//{{AFX_DATA(CRealFormView1)
enum { IDD = IDD_REAL1_FORM };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// .... and so on

Hope that help you

Axel