-
July 12th, 2004, 03:17 AM
#1
Setting Variables, Dialog Name in CMainframe
Good day to all!
i created a CDialog class CReportUI which is dynamically setting up its variables and dialog title called by CMainFrame class... here is my code snipet:
void CMainFrame::OnReportsManagerialreportComparativeVariance()
{
CReportUI dlgRepUI;
dlgRepUI.mc_ccType.AddString("BARANGAY");
dlgRepUI.mc_ccType.AddString("MAIN BUSINESS");
dlgRepUI.mc_ccType.AddString("OWNERSHIP KIND");
dlgRepUI.mc_ccType.AddString("BUSINESS STATUS");
dlgRepUI.mc_ccType.AddString("GROSS RANGE");
dlgRepUI.mc_ccType.AddString("CAPITAL RANGE");
dlgRepUI.DoModal();
}
CReportUI has a combo box object.... i get a debug assertion message... i also want to set the dialog title from it...
-
July 12th, 2004, 03:29 AM
#2
before DoModal your dialog window isn't created.
so you cannot set the dialogs title or add strings to your combobox (isn't created as well).
what you can do make 2 public member variables in your dialog:
CStringArray m_strarrComboStrings;
CString m_strCaption;
in your OnInitDialog of CReportUI (this method is called after your dialog window (and childwindows) are created) do
Code:
SetWindowText(m_strCaption);
for(int i=0; i<m_strarrCOmboStrings.GetSize(); i++)
mc_ccType.AddString(m_strarrComboStrings[i]);
UpdateData(FALSE);
and in CMainFrame::OnReportsManagerialreportComparativeVariance
Code:
CReportUI dlgRepUI;
dlgRepUI.m_strarrComboStrings.Add("bla1");
dlgRepUI.m_strarrComboStrings.Add("bla2");
...
dlgRepUI.m_strCaption = "Dialog 0815";
dlgRepUI.DoModal();
there are 10 kinds of people. those who understand binary and those who don't...
rate a post if you find it usefull, thx
check out my Firefox/Mozilla Extension: http://urlparams.blogwart.com/
-
July 12th, 2004, 03:30 AM
#3
CReportUI has a combo box object.... i get a debug assertion message
Thats because you add the strings to a control which has not been created yet.
i also want to set the dialog title from it...
You should do both in CReportUI::OnInitDialog.
-
July 12th, 2004, 03:31 AM
#4
That happens because your combo box control is not created. Declaring a CReportUI object does not create the window (and the combo); that happens only when calling DoModal(). So you cannot add strings to the combo this way. Perhaps pass them as a CStringList to the CReportUI in a member attribute, and in OnInitDialog() fill the combo with the strings.
-
July 12th, 2004, 03:33 AM
#5
again, posted the same time with others... that happens a lot to me lately...
-
July 12th, 2004, 03:38 AM
#6
in your OnInitDialog of CReportUI (this method is called after your dialog window (and childwindows) are created) do
Code:
SetWindowText(m_strCaption);
for(int i=0; i<m_strarrCOmboStrings.GetSize(); i++)
mc_ccType.AddString(m_strarrComboStrings[i]);
UpdateData(FALSE);
one short picky remark: The UpdateData(FALSE) is not needed in OnInitDialog
Last edited by Alin; July 12th, 2004 at 03:43 AM.
-
July 12th, 2004, 03:46 AM
#7
-
July 12th, 2004, 05:20 AM
#8
thanks a lot guys... i already adopt the code and now it runs smoothly... another thing can anyone check this body code of mine... can this create memory leaks?
//HEADER CLASS
#include "BPLS Assessment.h"
class CManagerialReport
{
public:
void RetrieveStatus();
void Initialization();
void RetrieveOwnKind();
CStringArray m_sArrOwnKind,m_sArrBnsStat;
CManagerialReport();
virtual ~CManagerialReport();
private:
CString sQuery;
CBPLSAssessmentApp *pApp;
_RecordsetPtr pSet;
};
//CPP FILE
#include "stdafx.h"
#include "BPLS Assessment.h"
#include "CManagerialReport.h"
CManagerialReport::CManagerialReport()
{
pApp = (CBPLSAssessmentApp*)AfxGetApp();
pSet.CreateInstance(__uuidof(Recordset));
}
CManagerialReport::~CManagerialReport()
{
}
void CManagerialReport::Initialization()
{
sQuery = "";
if (m_sArrOwnKind.GetSize() > 1)
m_sArrOwnKind.RemoveAll();
else
m_sArrOwnKind.FreeExtra();
}
void CManagerialReport::RetrieveOwnKind()
{
try {
sQuery = "select distinct orgn_kind from businesses order by orgn_kind desc";
pSet->Open(_bstr_t(sQuery),pApp->m_pConnection.GetInterfacePtr(),adOpenStatic,adLockReadOnly,adCmdText);
if (!pSet->adoEOF)
{
while (!pSet->adoEOF){
m_sArrOwnKind.Add(pApp->TrimAll(pApp->GetStrVariant(pSet->GetCollect("orgn_kind"))));
pSet->MoveNext();
}
}
pSet->Close();
}
catch (_com_error &e)
{
_bstr_t bstrDescription(e.Description());
MessageBox(NULL,"CManagerialReport:RetrieveOwnKind\n"+bstrDescription,"CManagerialReport",MB_OK);
exit(1);
}
}
void CManagerialReport::RetrieveStatus()
{
try {
sQuery = "select distinct bns_stat from businesses order by bns_stat desc";
pSet->Open(_bstr_t(sQuery),pApp->m_pConnection.GetInterfacePtr(),adOpenStatic,adLockReadOnly,adCmdText);
if (!pSet->adoEOF)
{
while (!pSet->adoEOF){
m_sArrBnsStat.Add(pApp->TrimAll(pApp->GetStrVariant(pSet->GetCollect("bns_stat"))));
pSet->MoveNext();
}
}
pSet->Close();
}
catch (_com_error &e)
{
_bstr_t bstrDescription(e.Description());
MessageBox(NULL,"CManagerialReport:RetrieveStatus\n"+bstrDescription,"CManagerialReport",MB_OK);
exit(1);
}
}
can anyone give me techniques if these can create memory leaks.. and one thing also, can anyone give me an e-book about STL and C++ reference.... thanks again
Last edited by Andreas Masur; July 13th, 2004 at 03:07 AM.
-
July 12th, 2004, 05:27 AM
#9
Run your code in debug mode and watch the messages in the debug console. If you have memory leaks they will be prompted there.
-
July 12th, 2004, 12:49 PM
#10
how will i know that my program have memory leaks in debug mode? i know that the program seems to run smoothly but internally or during running, it is possible to acquire memory resources and memory leaks so i can patch or prevent it from happening...
and also can anyone give me a good e-book reference(downloadable, sites or send thru email) about C++ or STL... thanks again
-
July 13th, 2004, 12:18 AM
#11
as a follow up of my question... thats all
-
July 13th, 2004, 03:01 AM
#12
If you run in debug mode (F5) and have memory leaks, you'll be promted, with something like:
Code:
Detected memory leaks!
Dumping objects ->
D:\Marius\VisualC++\TabTest\TabTestDlg.cpp(174) : {85} normal block at 0x00325230, 40 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
D:\Marius\VisualC++\TabTest\TabTestDlg.cpp(148) : {81} client block at 0x00325090, subtype 0, 96 bytes long.
a CDialog object at $00325090, 96 bytes long
D:\Marius\VisualC++\TabTest\TabTestDlg.cpp(141) : {76} client block at 0x00324FE8, subtype 0, 108 bytes long.
a CDialog object at $00324FE8, 108 bytes long
Object dump complete.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|