Print Page | Close Window

[solved] Report Control crash on removing selected

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Report Control
Forum Description: Topics Related to Codejock Report Control
URL: http://forum.codejock.com/forum_posts.asp?TID=23109
Printed Date: 28 April 2024 at 2:15pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: [solved] Report Control crash on removing selected
Posted By: jmarcosf
Subject: [solved] Report Control crash on removing selected
Date 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.



Replies:
Posted By: olebed
Date 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


Posted By: olebed
Date 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());
    }
}


Posted By: jmarcosf
Date Posted: 25 August 2016 at 11:38am
Now OnRemoveRoEx() works fine for me.
Thanks a lot!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net