views:

324

answers:

1

My CFormView-derived class is structured as follows:

class FormViewClass : public CFormView
{
     ...
     FormViewClass();
     void Initialize();
     virtual void OnInitialUpdate();
     ...
};

Ideally, I would like to call the Initialize() function in the body of the constructor as follows:

FormViewClass::FormViewClass()
{
        ...
     // originally I want to call Initialize function here
     Initialize();
        ...
}

However, since I want this function to be responsible for all the initialization of this class when being created, and it contains MFC objects initializations such as combobox, edit control, checkbox control, radio button control, etc., should I be instead calling the Initialize() function here as I thought:

void FormViewClass::OnInitialUpdate()
{
    // Should I call Initialize function instead here?
    Initialize();
}

Currently I have non-MFC memory and object initialization in the constructor (hence calling Iniitalize() helper function in the constructor) and MFC object iniitalization in the OnIniitalUpdate() handler function. It would be great to hear your thoughts about it so that I can refactor the code properly. Thanks in advance.

+6  A: 

I think you're right to do it the way you're doing it.

In general, I would try to initialise things as early as possible (but no earlier 8-) so doing non-GUI stuff in the constructor, and GUI stuff in OnInitialUpdate makes sense.

(If OnInitDialog existed for CFormView, that would probably be a better place than OnInitialUpdate, but I don't think it does.)

RichieHindle
No it doesn't. AFAIK, OnInitialUpdate is the equivalent of OnInitDialog for CFormView class. Thanks for your thoughts.
stanigator