'Forward Class Declaration' Not Working
-
hello guys... I am having a debug assertion when trying to use forward class declaration. Basically I have this CMyTabCtrl inwhich I have forward declared two dialog class, like this: CMyTabCtrl.h
class CTabOneDlg;
class CTabTwoDlg;And now in the implementaion file, I am using these pointers to create instances of two dialogs and add them to the TabCtrl. Here are the constructor and the InitializeTabs() functions. CMyTabCtrl.cpp
CMyTabCtrl::CMyTabCtrl()
{
m_arrTabs[0] = new CTabOneDlg; //CDialog* m_arrTabs[2];
m_arrTabs[1] = new CTabTwoDlg;m_tabOne = (CTabOneDlg*)m_arrTabs[0]; // CTabOneDlg* m_tabOne;
m_tabTwo = (CTabTwoDlg*)m_arrTabs[1]; // CTabTwoDlg* m_tabTwo;
}coid CMyTabCtrl::InitializeTabs()
{
this->InsertItem(0, _T("Faculty"));
this->InsertItem(1, _T("Admin"));//create the dialogs m\_arrTabs\[0\]->Create(IDD\_TAB1\_DLG, this); m\_arrTabs\[1\]->Create(IDD\_TAB2\_DLG, this); //show the firs and hide the rest m\_arrTabs\[0\]->ShowWindow(SW\_SHOW); m\_arrTabs\[1\]->ShowWindow(SW\_HIDE);
}
And finally when in MainDialogDlg.cpp, I try to forward declare this CMyTabCtrl class, it gives debug assertion on the second line of the InitializeTabs() function. CMainDialogDlg.h
class CMyTabCtrl;
CMyTabCtrl *tabCtrl;
CMainDialogDlg.cpp
BOOL CMainDialogDlg::OnInitDialog()
{
tabCtrl = new CMyTabCtrl;
tabCtrl->InitizlizeTabs();
}The debug assertion it gives is as follows
mfc100ud.dll!CTabCtrl::InsertItem(int nItem, const wchar_t * lpszItem) Line 570 + 0x2d bytes C++
Why it is giving debug assertion on the InsertItem() function in the InitializeTabs() function. Thanks for at least giving time to read it.
This world is going to explode due to international politics, SOON.
-
hello guys... I am having a debug assertion when trying to use forward class declaration. Basically I have this CMyTabCtrl inwhich I have forward declared two dialog class, like this: CMyTabCtrl.h
class CTabOneDlg;
class CTabTwoDlg;And now in the implementaion file, I am using these pointers to create instances of two dialogs and add them to the TabCtrl. Here are the constructor and the InitializeTabs() functions. CMyTabCtrl.cpp
CMyTabCtrl::CMyTabCtrl()
{
m_arrTabs[0] = new CTabOneDlg; //CDialog* m_arrTabs[2];
m_arrTabs[1] = new CTabTwoDlg;m_tabOne = (CTabOneDlg*)m_arrTabs[0]; // CTabOneDlg* m_tabOne;
m_tabTwo = (CTabTwoDlg*)m_arrTabs[1]; // CTabTwoDlg* m_tabTwo;
}coid CMyTabCtrl::InitializeTabs()
{
this->InsertItem(0, _T("Faculty"));
this->InsertItem(1, _T("Admin"));//create the dialogs m\_arrTabs\[0\]->Create(IDD\_TAB1\_DLG, this); m\_arrTabs\[1\]->Create(IDD\_TAB2\_DLG, this); //show the firs and hide the rest m\_arrTabs\[0\]->ShowWindow(SW\_SHOW); m\_arrTabs\[1\]->ShowWindow(SW\_HIDE);
}
And finally when in MainDialogDlg.cpp, I try to forward declare this CMyTabCtrl class, it gives debug assertion on the second line of the InitializeTabs() function. CMainDialogDlg.h
class CMyTabCtrl;
CMyTabCtrl *tabCtrl;
CMainDialogDlg.cpp
BOOL CMainDialogDlg::OnInitDialog()
{
tabCtrl = new CMyTabCtrl;
tabCtrl->InitizlizeTabs();
}The debug assertion it gives is as follows
mfc100ud.dll!CTabCtrl::InsertItem(int nItem, const wchar_t * lpszItem) Line 570 + 0x2d bytes C++
Why it is giving debug assertion on the InsertItem() function in the InitializeTabs() function. Thanks for at least giving time to read it.
This world is going to explode due to international politics, SOON.
In which files have you #included the tab dialog and tab control headers?
«_Superman_» _I love work. It gives me something to do between weekends.
-
hello guys... I am having a debug assertion when trying to use forward class declaration. Basically I have this CMyTabCtrl inwhich I have forward declared two dialog class, like this: CMyTabCtrl.h
class CTabOneDlg;
class CTabTwoDlg;And now in the implementaion file, I am using these pointers to create instances of two dialogs and add them to the TabCtrl. Here are the constructor and the InitializeTabs() functions. CMyTabCtrl.cpp
CMyTabCtrl::CMyTabCtrl()
{
m_arrTabs[0] = new CTabOneDlg; //CDialog* m_arrTabs[2];
m_arrTabs[1] = new CTabTwoDlg;m_tabOne = (CTabOneDlg*)m_arrTabs[0]; // CTabOneDlg* m_tabOne;
m_tabTwo = (CTabTwoDlg*)m_arrTabs[1]; // CTabTwoDlg* m_tabTwo;
}coid CMyTabCtrl::InitializeTabs()
{
this->InsertItem(0, _T("Faculty"));
this->InsertItem(1, _T("Admin"));//create the dialogs m\_arrTabs\[0\]->Create(IDD\_TAB1\_DLG, this); m\_arrTabs\[1\]->Create(IDD\_TAB2\_DLG, this); //show the firs and hide the rest m\_arrTabs\[0\]->ShowWindow(SW\_SHOW); m\_arrTabs\[1\]->ShowWindow(SW\_HIDE);
}
And finally when in MainDialogDlg.cpp, I try to forward declare this CMyTabCtrl class, it gives debug assertion on the second line of the InitializeTabs() function. CMainDialogDlg.h
class CMyTabCtrl;
CMyTabCtrl *tabCtrl;
CMainDialogDlg.cpp
BOOL CMainDialogDlg::OnInitDialog()
{
tabCtrl = new CMyTabCtrl;
tabCtrl->InitizlizeTabs();
}The debug assertion it gives is as follows
mfc100ud.dll!CTabCtrl::InsertItem(int nItem, const wchar_t * lpszItem) Line 570 + 0x2d bytes C++
Why it is giving debug assertion on the InsertItem() function in the InitializeTabs() function. Thanks for at least giving time to read it.
This world is going to explode due to international politics, SOON.
This has nothing to do with forward declaration; that is merely a convenience for the compiler. You should look more closely at the actual code, and use your debugger to step through and try to see which variable is causing the actual assertion.
Programming is work, it isn't finger painting. Luc Pattyn
-
In which files have you #included the tab dialog and tab control headers?
«_Superman_» _I love work. It gives me something to do between weekends.
Tab Dialog are #included in CMyTabCtrl.cpp like this CMyTabCtrl.h
class CTabOneDlg;
class CTabTwoDlg;CMyTabCtrl.cpp (Constructor)
m_arrTabs[0] = new CTabOneDlg; //CDialog* m_arrTabs[2];
m_arrTabs[1] = new CTabTwoDlg;While the class for Tab control is #included in main dialog like this. CMainDialogDlg.h
class CMyTabCtrl;
public:
CMyTabCtrl *tabCtrl;CMainDialogDlg.cpp (OnInitDialog)
tabCtrl = new CMyTabCtrl; tabCtrl->InitizlizeTabs();
BTW, this application works fine if I dont use forward decaration method and #include all the files, normally the way we do.
This world is going to explode due to international politics, SOON.
-
This has nothing to do with forward declaration; that is merely a convenience for the compiler. You should look more closely at the actual code, and use your debugger to step through and try to see which variable is causing the actual assertion.
Programming is work, it isn't finger painting. Luc Pattyn
Yes. I did exactly that. Everything works fine if I #include all the header files normally. The variable that acrually causing the problem is tabCtrl. It gives debug assertion in the second line of the InitializeTabs() function. The assertion it gives is as follows.
mfc100ud.dll!CTabCtrl::InsertItem(int nItem, const wchar_t * lpszItem) Line 570 + 0x2d bytes C++
And if you see the second line of the the said function then you will notice that it is merely inserting the tab dialog at the specified location like this
this->InsertItem(0, _T("Faculty"));
this->InsertItem(1, _T("Admin"));So this should not be a problme I think.
This world is going to explode due to international politics, SOON.
-
Yes. I did exactly that. Everything works fine if I #include all the header files normally. The variable that acrually causing the problem is tabCtrl. It gives debug assertion in the second line of the InitializeTabs() function. The assertion it gives is as follows.
mfc100ud.dll!CTabCtrl::InsertItem(int nItem, const wchar_t * lpszItem) Line 570 + 0x2d bytes C++
And if you see the second line of the the said function then you will notice that it is merely inserting the tab dialog at the specified location like this
this->InsertItem(0, _T("Faculty"));
this->InsertItem(1, _T("Admin"));So this should not be a problme I think.
This world is going to explode due to international politics, SOON.
Overloaded_Name wrote:
It gives debug assertion
Yes, but what assertion; what is the value (or missing value) that actually causes the assertion?
Programming is work, it isn't finger painting. Luc Pattyn
-
Overloaded_Name wrote:
It gives debug assertion
Yes, but what assertion; what is the value (or missing value) that actually causes the assertion?
Programming is work, it isn't finger painting. Luc Pattyn
It just takes me to this line in afxcmn.inl
{ ASSERT(::IsWindow(m\_hWnd)); return CTabCtrl::InsertItem(TCIF\_TEXT, nItem, lpszItem, 0, 0); }
If I see in the locals then I find these values
this 0x0019fc18 {CMyTabCtrl hWnd=0x00000000} CTabCtrl * const
nItem 0 intIf there is something else I should look for, then tell me.
This world is going to explode due to international politics, SOON.
-
It just takes me to this line in afxcmn.inl
{ ASSERT(::IsWindow(m\_hWnd)); return CTabCtrl::InsertItem(TCIF\_TEXT, nItem, lpszItem, 0, 0); }
If I see in the locals then I find these values
this 0x0019fc18 {CMyTabCtrl hWnd=0x00000000} CTabCtrl * const
nItem 0 intIf there is something else I should look for, then tell me.
This world is going to explode due to international politics, SOON.
That clearly shows that
CMyTabCtrl
has not been created properly, as it does not have a Window associated with it. You need to look at where you create it to try to discover why the create is failing, or why it has not been called properly.Programming is work, it isn't finger painting. Luc Pattyn
-
hello guys... I am having a debug assertion when trying to use forward class declaration. Basically I have this CMyTabCtrl inwhich I have forward declared two dialog class, like this: CMyTabCtrl.h
class CTabOneDlg;
class CTabTwoDlg;And now in the implementaion file, I am using these pointers to create instances of two dialogs and add them to the TabCtrl. Here are the constructor and the InitializeTabs() functions. CMyTabCtrl.cpp
CMyTabCtrl::CMyTabCtrl()
{
m_arrTabs[0] = new CTabOneDlg; //CDialog* m_arrTabs[2];
m_arrTabs[1] = new CTabTwoDlg;m_tabOne = (CTabOneDlg*)m_arrTabs[0]; // CTabOneDlg* m_tabOne;
m_tabTwo = (CTabTwoDlg*)m_arrTabs[1]; // CTabTwoDlg* m_tabTwo;
}coid CMyTabCtrl::InitializeTabs()
{
this->InsertItem(0, _T("Faculty"));
this->InsertItem(1, _T("Admin"));//create the dialogs m\_arrTabs\[0\]->Create(IDD\_TAB1\_DLG, this); m\_arrTabs\[1\]->Create(IDD\_TAB2\_DLG, this); //show the firs and hide the rest m\_arrTabs\[0\]->ShowWindow(SW\_SHOW); m\_arrTabs\[1\]->ShowWindow(SW\_HIDE);
}
And finally when in MainDialogDlg.cpp, I try to forward declare this CMyTabCtrl class, it gives debug assertion on the second line of the InitializeTabs() function. CMainDialogDlg.h
class CMyTabCtrl;
CMyTabCtrl *tabCtrl;
CMainDialogDlg.cpp
BOOL CMainDialogDlg::OnInitDialog()
{
tabCtrl = new CMyTabCtrl;
tabCtrl->InitizlizeTabs();
}The debug assertion it gives is as follows
mfc100ud.dll!CTabCtrl::InsertItem(int nItem, const wchar_t * lpszItem) Line 570 + 0x2d bytes C++
Why it is giving debug assertion on the InsertItem() function in the InitializeTabs() function. Thanks for at least giving time to read it.
This world is going to explode due to international politics, SOON.
Since the assertion indicates that the mhWnd is NULL, the problem lies in this area:
Overloaded_Name wrote:
BOOL CMainDialogDlg::OnInitDialog() { tabCtrl = new CMyTabCtrl; tabCtrl->InitizlizeTabs(); }
The first line creates an instance of the class, but does not create the window associated with it. The second line tries to insert information into the window - but there is none. As Richard MacCutchen said, you need to Create the tab control. Hope this helps.
Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
Since the assertion indicates that the mhWnd is NULL, the problem lies in this area:
Overloaded_Name wrote:
BOOL CMainDialogDlg::OnInitDialog() { tabCtrl = new CMyTabCtrl; tabCtrl->InitizlizeTabs(); }
The first line creates an instance of the class, but does not create the window associated with it. The second line tries to insert information into the window - but there is none. As Richard MacCutchen said, you need to Create the tab control. Hope this helps.
Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
Well spotted, I failed to notice this obvious mistake.
Programming is work, it isn't finger painting. Luc Pattyn
-
Since the assertion indicates that the mhWnd is NULL, the problem lies in this area:
Overloaded_Name wrote:
BOOL CMainDialogDlg::OnInitDialog() { tabCtrl = new CMyTabCtrl; tabCtrl->InitizlizeTabs(); }
The first line creates an instance of the class, but does not create the window associated with it. The second line tries to insert information into the window - but there is none. As Richard MacCutchen said, you need to Create the tab control. Hope this helps.
Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
krmed wrote:
The first line creates an instance of the class, but does not create the window associated with it.
Ok. I understand where the problem lies. But that's what I stated in my OP. If I do this application normally, like #including the tab files in the Tab Ctrl header file and then, #including this tab cntrl header file in the main dialog header file. And finally when I do
CMyTabCtrl tabCtrl;
tabCtrl.InitializeTabs();It works perfectly. However thank you for your time. I am trying to do this, in this way as well.
This world is going to explode due to international politics, SOON.