Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Report Control
  New Posts New Posts RSS Feed - [solved] Report Control crash on removing selected
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

[solved] Report Control crash on removing selected

 Post Reply Post Reply
Author
Message
jmarcosf View Drop Down
Groupie
Groupie


Joined: 22 June 2006
Status: Offline
Points: 27
Post Options Post Options   Thanks (0) Thanks(0)   Quote jmarcosf Quote  Post ReplyReply Direct Link To This Post Topic: [solved] Report Control crash on removing selected
    Posted: 24 August 2016 at 10:48am
I think I've found a bug on Report Control.
On a Report Control, if you select several items and then you want to delete them you get a malfunctioning behaviour. Using RemoveRowEx() method will not remove all of selected rows and if you use RemoveRecordEx() application will crash.

This can be viewed using ReportControl.ReportSample sample as following:
Step 1- Select REPORT CONTROL menu item, then select "Quality Assurance->Notifications".
Step 2- Select Item 0, 0 to item 19,0.
Step 3- Press Remove Row Ex button. Only a few rows will be deleted.
Step 4- After restarting the application and selecting the same groups of rows but this time you press Remove Record Ex button application will crash.
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post Posted: 24 August 2016 at 11:52am
Hello jmarcosf,

I think we fixed this recently. Please check this with next beta or release.

Problem was in method CXTPReportSection::RefreshIndexes(int nIndexStart). Code with using variable bSelected should be removed (include if blocks). It is for properly selection with pressed Ctrl button. And to make proper indexes refreshing on removing rows we add new  method OnDeletedRefreshIndexes
void CXTPReportSection::OnDeletedRefreshIndexes()
{
    int nRowCount = m_pRows->GetCount();

    for (int nIndex = 0; nIndex<nRowCount; nIndex++)
    {
        CXTPReportRow *pRow = NULL;

        if (m_pRows->m_pVirtualRow)
        {
            pRow = m_pRows->m_pVirtualRow;
            pRow->m_nIndex = nIndex;
        }
        else
        {
            // Direct access to increase performance
            pRow = m_pRows->m_arrRows.m_pData[nIndex];
        }

        if (NULL != pRow)
        {
            BOOL bSelected = GetSelectedRows()->Contains(pRow);
            if (bSelected)
            {
                GetSelectedRows()->Remove(pRow);
            }

            pRow->m_nIndex = nIndex;
            ASSERT(pRow->IsVisible());

            if (bSelected)
            {
                GetSelectedRows()->Add(pRow);
            }
        }
    }
}
void CXTPReportSection::RefreshIndexes(int nIndexStart)
{
    int nRowCount = m_pRows->GetCount();
    nIndexStart = nIndexStart < 0 ? 0 : nIndexStart;

    for (int nIndex=nIndexStart; nIndex<nRowCount; nIndex++)
    {
        CXTPReportRow *pRow = NULL;

        if (m_pRows->m_pVirtualRow)
        {
            pRow = m_pRows->m_pVirtualRow;
            pRow->m_nIndex = nIndex;
        }
        else
        {
            // Direct access to increase performance
            pRow = m_pRows->m_arrRows.m_pData[nIndex];
        }

        if (NULL != pRow)
        {
            pRow->m_nIndex = nIndex;
            ASSERT(pRow->IsVisible());
        }
    }
}
which like old RefreshIndexes().   And then in CXTPReportSection::RemoveRecordEx  RefreshIndexes() should be replaced with  OnDeletedRefreshIndexes().

Regards,
 Oleksandr Lebed
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post Posted: 24 August 2016 at 12:08pm
also different methods of removing rows and records had different results (crashes or not)

next sample method removes incorrect  before and after fix
Samples\ReportControl\ReportSample\TestNotificationsDlg.cpp
void CTestNotificationsDlg::OnRemoveRowEx()
{
    CXTPReportSelectedRows *pSelectedRows = m_wndReport.GetSelectedRows();

    for (int nRow=0; nRow<pSelectedRows->GetCount(); nRow++)
    {
        CXTPReportRow *pRow = pSelectedRows->GetAt(nRow);
        m_wndReport.RemoveRowEx(pRow);
    }
}

void CTestNotificationsDlg::OnRemoveRecordEx()
{
    CXTPReportSelectedRows *pSelectedRows = m_wndReport.GetSelectedRows();

    for (int nRow=0; nRow<pSelectedRows->GetCount(); nRow++)
    {
        CXTPReportRow *pRow = pSelectedRows->GetAt(nRow);
        m_wndReport.RemoveRecordEx(pRow->GetRecord());
    }
}


next code is correct
void CTestNotificationsDlg::OnRemoveRowEx()
{
    CXTPReportSelectedRows *pSelectedRows = m_wndReport.GetSelectedRows();

    while (pSelectedRows->GetCount() > 0)
    {
        m_wndReport.RemoveRowEx(pSelectedRows->GetAt(pSelectedRows->GetCount() - 1));
    }
}

void CTestNotificationsDlg::OnRemoveRecordEx()
{
    CXTPReportSelectedRows *pSelectedRows = m_wndReport.GetSelectedRows();

    while (pSelectedRows->GetCount() > 0)
    {
        CXTPReportRow *pRow = pSelectedRows->GetAt(pSelectedRows->GetCount() - 1);
        m_wndReport.RemoveRecordEx(pRow->GetRecord());
    }
}
Back to Top
jmarcosf View Drop Down
Groupie
Groupie


Joined: 22 June 2006
Status: Offline
Points: 27
Post Options Post Options   Thanks (0) Thanks(0)   Quote jmarcosf Quote  Post ReplyReply Direct Link To This Post Posted: 25 August 2016 at 11:38am
Now OnRemoveRoEx() works fine for me.
Thanks a lot!
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.141 seconds.