CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Feb 2004
    Location
    Philippines
    Posts
    58

    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...

  2. #2
    Join Date
    May 2004
    Location
    Germany
    Posts
    655
    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/

  3. #3
    Join Date
    Aug 1999
    Location
    Germany
    Posts
    2,338
    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.

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360
    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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360
    again, posted the same time with others... that happens a lot to me lately...
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  6. #6
    Join Date
    Feb 2002
    Posts
    3,788

    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.

  7. #7
    Join Date
    May 2004
    Location
    Germany
    Posts
    655
    okok... right

    i'm a fan of doing things twice!!
    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/

  8. #8
    Join Date
    Feb 2004
    Location
    Philippines
    Posts
    58
    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.

  9. #9
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360
    Run your code in debug mode and watch the messages in the debug console. If you have memory leaks they will be prompted there.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  10. #10
    Join Date
    Feb 2004
    Location
    Philippines
    Posts
    58
    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

  11. #11
    Join Date
    Feb 2004
    Location
    Philippines
    Posts
    58
    as a follow up of my question... thats all

  12. #12
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360
    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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured