Print Page | Close Window

Possible exception after RemoveRecordEx calling

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=24531
Printed Date: 04 December 2024 at 1:14pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Possible exception after RemoveRecordEx calling
Posted By: DiZSl
Subject: Possible exception after RemoveRecordEx calling
Date Posted: 29 November 2024 at 1:40am
After calling RemoveRecordEx, it is essential to call UpdateWindows for the ReportControl. If this is not done and a user quickly clicks on the deleted record before the window is redrawn (updated), the function HitTest in CXTPReportControl::OnButton will return the deleted CXTPReportRow from the m_pScreenRows array, which is only updated during redrawing. However, the redraw has not yet occurred only invalidating, resulting in m_pScreenRows being out of sync with the main tree.

Additionally, when calling CXTPReportControl::OnButton, this removed CXTPReportRow will be passed to _SetSelectedRow, which will cause an index for a non-existent record to appear in the m_pSelectedRows array. As a result, m_pSelectedRows.GetCount will return 1, while m_pSelectedRows.GetAt(0) will return nullptr.

My solution (remove row from m_pScreenRows):
void CXTPReportRows::RemoveAt(int nIndex)
{
    auto row = m_arrRows.GetAt(nIndex);
    if (row != nullptr)
    {
        auto rows = GetScreenRows();
        if (rows != nullptr)
        {
            auto size = rows->GetCount();
            for (int i = 0; i < size; i++)
            {
                if (rows->GetAt(i) == row)
                {
                    row->InternalRelease();
                    rows->RemoveAt(i);
                    break;
                }
            }
        }

        row->InternalRelease();
    }
    m_arrRows.RemoveAt(nIndex);
}




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