Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Crash in ProfUIS_Controls Collapse All
Subject Author Date
Offer Har Nov 13, 2010 - 9:45 PM

Hi,


1. Download the ProfUIS_Controls sample from your site


2. Go to the grid page


3. Go to the SystemNumber column


4. Try to convert the numbers to negative by adding - before the number


The application crashes.


Ron.


 

Technical Support Nov 15, 2010 - 7:37 AM

Thank you for reporting this issue. Please update the source code for the following method:

void CExtGridCellSystemNumberCurrencyBase::TextGet( CExtSafeString & strCopy ) const
{
            __EXT_DEBUG_GRID_ASSERT_VALID( this );
            strCopy.Empty();
LCID _LCID = LANG_USER_DEFAULT;
            if( g_ResourceManager->IsCustomLangAllowed() )
                        _LCID = g_ResourceManager->GetLangIdDesired();
e_internal_mode_t eim = _QueryInternalMode();
HRESULT hr = E_FAIL;
BSTR _bstr = NULL;
            switch( eim )
            {
            case eim_number:
            {
                        long double lfValue = LongDoubleGet();
                        hr = ::VarBstrFromR8( (DOUBLE)lfValue, _LCID, 0, &_bstr );
                        if( FAILED( hr ) )
                                    break;
                        __EXT_DEBUG_GRID_ASSERT( _bstr != NULL );
                        CExtSafeString _strNegativeSign, _strDecimalPoint, _strGroupSeparator;
                        INT m_nNegativeFormatIndex;
                        CList < INT, INT > m_listDigitGrouping;
                        // negative sign
                        if( g_ResourceManager->GetLocaleInfo( LOCALE_SNEGATIVESIGN, NULL, 0 ) )
                        {
                                    g_ResourceManager->GetLocaleInfo( LOCALE_SNEGATIVESIGN, _strNegativeSign.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
                                    _strNegativeSign.ReleaseBuffer();
                        }
                        // decimal point
                        if( g_ResourceManager->GetLocaleInfo( LOCALE_SDECIMAL, NULL, 0 ) )
                                    g_ResourceManager->GetLocaleInfo( LOCALE_SDECIMAL, _strDecimalPoint.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
                        _strDecimalPoint.ReleaseBuffer();
                        // group separator
                        if( g_ResourceManager->GetLocaleInfo( LOCALE_STHOUSAND, NULL, 0 ) )
                                    g_ResourceManager->GetLocaleInfo( LOCALE_STHOUSAND, _strGroupSeparator.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
                        _strGroupSeparator.ReleaseBuffer();
                        TCHAR cNegNumFormatIndex = _T(’0’);
                        if( g_ResourceManager->GetLocaleInfo( LOCALE_INEGNUMBER, NULL, 0 ) )
                                    g_ResourceManager->GetLocaleInfo( LOCALE_INEGNUMBER, &cNegNumFormatIndex, sizeof( cNegNumFormatIndex ) );
                        m_nNegativeFormatIndex = _ttoi( & cNegNumFormatIndex );
                        CExtSafeString strDigitGrouping = _T("0");
                        if( g_ResourceManager->GetLocaleInfo( LOCALE_SGROUPING, NULL, 0 ) )
                        {
                                    g_ResourceManager->GetLocaleInfo( LOCALE_SGROUPING, strDigitGrouping.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
                                    strDigitGrouping.ReleaseBuffer();
                                    INT nStrLen = INT( strDigitGrouping.GetLength() );
                                    CExtSafeString _strGroup = _T("");
                                    INT nGroup = 0;
                                    if( m_listDigitGrouping.GetCount() > 0 )
                                                m_listDigitGrouping.RemoveAll();
                                    for( INT i = 0; i < nStrLen; i++ )
                                    {
                                                TCHAR ch = strDigitGrouping[i];
                                                if( ch == _T(’;’) )
                                                {
                                                            nGroup = _ttoi( _strGroup );
                                                            m_listDigitGrouping.AddTail( nGroup );
                                                            _strGroup = _T("");
                                                            nGroup = 0;
                                                }
                                                else
                                                            _strGroup = _strGroup + ch;
                                    }
                                    nGroup = _ttoi( _strGroup );
                                    m_listDigitGrouping.AddTail( nGroup );
                        }
                        // ensure the separators are not the same
                        if(                     _strDecimalPoint == _strGroupSeparator
                                    &&        (           _strDecimalPoint == _T(".")
                                    ||           _strDecimalPoint == _T(",")
                                    )
                                    )
                                    _strGroupSeparator = ( _strDecimalPoint == _T(",") ? _T(".") : _T(",") );
                        if(                     _strDecimalPoint == _strGroupSeparator
                                    &&        (           _strDecimalPoint != _T(".")
                                    &&        _strDecimalPoint != _T(",")
                                    )
                                    )
                                    _strDecimalPoint == _T(".");
                        USES_CONVERSION;
                        strCopy = OLE2CT( _bstr );
                        CExtSafeString strTextChange;
                        INT nDecimalSeparatorLen = INT( _strDecimalPoint.GetLength() );
                        bool bInsertNegativeSign = ( lfValue < 0 );
                        if( bInsertNegativeSign )
                        {
                                    INT nNegSignPos = strCopy.Find( _T(’-’) );
                                    strCopy.Delete( nNegSignPos );
                        }
                        if( _strDecimalPoint != _T(’.’) )
                        {
                                    INT nPosDot = strCopy.Find( _T(’.’) );
                                    if( nPosDot >= 0 )
                                    {
                                                strCopy.Delete( nPosDot );
                                                strCopy.Insert( nPosDot, _strDecimalPoint );
                                    }
                        }
                        INT nPositionDecimalPoint = INT( strCopy.Find( _strDecimalPoint ) );
                        INT nTextLen = INT( strCopy.GetLength() );
                        INT nWholeNumber = ( ( nPositionDecimalPoint >= 0 ) ? ( ( nPositionDecimalPoint < m_nMaxWholeDigits ) ? nPositionDecimalPoint : m_nMaxWholeDigits ) : ( ( m_nMaxWholeDigits >= nTextLen ) ?  nTextLen : m_nMaxWholeDigits ) );
                        INT nDecimalPointLen = nDecimalSeparatorLen; // 1
                        INT nCorectTextLen = nWholeNumber + nDecimalPointLen + m_nMaxFractionDigits;
                        nCorectTextLen = ( nCorectTextLen > nTextLen ) ? nTextLen : nCorectTextLen;
                        INT nCountDigitGroups = INT( m_listDigitGrouping.GetCount() );
                        CList < INT, INT > _listPos;
                        bool bLastZiro = ( m_listDigitGrouping.GetAt( m_listDigitGrouping.FindIndex( nCountDigitGroups - 1 ) ) == 0 ) ? true : false;
                        __EXT_DEBUG_GRID_ASSERT( nWholeNumber <= m_nMaxWholeDigits );
                        INT nPos = nWholeNumber;
                        INT i = 0;
                        INT nPreviousCount = -1;
                        for( ; true; )
                        {
                                    INT nCount = INT( m_listDigitGrouping.GetAt( m_listDigitGrouping.FindIndex(i) ) );
                                    if( nCount == 0 && i < ( nCountDigitGroups - 1 ) )
                                                break;
                                    if( nCount == 0 && i == ( nCountDigitGroups - 1 ) )
                                    {
                                                __EXT_DEBUG_GRID_ASSERT( nPreviousCount != -1 );
                                                nCount = nPreviousCount;
                                    }
                                    nPos -= nCount;
                                    if( nPos > 0 )
                                                _listPos.AddHead( nPos - 1 );
                                    else
                                                break;
                                    if( i == ( nCountDigitGroups - 1 ) && ! bLastZiro )
                                                break;
                                    if( i < ( nCountDigitGroups - 1 ) )
                                                i ++;
                                    nPreviousCount = nCount;
                        }
                        INT nCurDigitPos = 0;
                        INT nPosCount = INT( _listPos.GetCount() );
                        bool bCanPastGroupSep = ( nPosCount > 0 );
                        for( i = 0; i < nCorectTextLen; i++ )
                        {
                                    TCHAR _tchr = strCopy[i];
                                    strTextChange += _tchr;
                                    bool bInsertSign = false;
                                    INT nPosCur = 0;
                                    if( bCanPastGroupSep )
                                                nPosCur = _listPos.GetAt( _listPos.FindIndex( nCurDigitPos ) );
                                    if(                     ( i <= nWholeNumber )
                                                &&        ( i != ( nCorectTextLen - 1 ) )
                                                &&        ( i == nPosCur )
                                                &&        bCanPastGroupSep
                                                )
                                    {
                                                strTextChange += _strGroupSeparator;
                                                bInsertSign = true;
                                                if( nCurDigitPos < ( nPosCount - 1 ) )
                                                            nCurDigitPos ++;
                                                else
                                                            bCanPastGroupSep = false;
                                    }
                                    if( i == ( nWholeNumber - 1 ) && ( nPositionDecimalPoint == -1 ) && ( i != nCorectTextLen - 1 ) )
                                                strTextChange += _strDecimalPoint;
                        }
                        if( bInsertNegativeSign && AllowNegativeGet() )
                        {
                                    CExtSafeString _strBeforNegSign = ( (m_nNegativeFormatIndex == 4) ? _T(" "): _T("") );
                                    CExtSafeString _strAfterNegSign = ( (m_nNegativeFormatIndex == 2) ? _T(" "): _T("") );
                                    CExtSafeString _strFirstPart = _strBeforNegSign + _strNegativeSign;
                                    CExtSafeString _strNegativeSign = _strFirstPart + _strAfterNegSign;
                                    if( m_nNegativeFormatIndex == 0 )
                                    {
                                                strTextChange.Insert( strTextChange.GetLength(), _T(")") );
                                                strTextChange.Insert( 0, _T("(") );
                                    }
                                    if( m_nNegativeFormatIndex == 1 || m_nNegativeFormatIndex == 2 )
                                                strTextChange.Insert( 0, _strNegativeSign );
                                    if( m_nNegativeFormatIndex == 3 || m_nNegativeFormatIndex == 4 )
                                                strTextChange.Insert( strTextChange.GetLength(), _strNegativeSign );
                        }
                        strCopy = strTextChange;
            }
            break;
            case eim_currency:
            {
                        long double lfValue = LongDoubleGet();
                        hr = ::VarBstrFromR8( (DOUBLE)lfValue, _LCID, 0, &_bstr );
                        if( FAILED( hr ) )
                                    break;
                        __EXT_DEBUG_GRID_ASSERT( _bstr != NULL );
                        CExtSafeString _strNegativeSign, _strDecimalPoint, _strGroupSeparator, _strCurrencySymbol;
                        INT m_nNegativeFormatIndex, m_nPositiveFormatIndex;
                        CList < INT, INT > m_listDigitGrouping;
                        // negative sign
                        if( g_ResourceManager->GetLocaleInfo( LOCALE_SNEGATIVESIGN, NULL, 0 ) )
                        {
                                    g_ResourceManager->GetLocaleInfo( LOCALE_SNEGATIVESIGN, _strNegativeSign.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
                                    _strNegativeSign.ReleaseBuffer();
                        }
                        if( g_ResourceManager->GetLocaleInfo( LOCALE_SCURRENCY, NULL, 0 ) )
                        {
                                    g_ResourceManager->GetLocaleInfo( LOCALE_SCURRENCY, _strCurrencySymbol.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
                                    _strCurrencySymbol.ReleaseBuffer();
                        }
                        // decimal point
                        if( g_ResourceManager->GetLocaleInfo( LOCALE_SMONDECIMALSEP, NULL, 0 ) )
                        {
                                    g_ResourceManager->GetLocaleInfo( LOCALE_SMONDECIMALSEP, _strDecimalPoint.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
                                    _strDecimalPoint.ReleaseBuffer();
                        }
                        // Get group separator
                        if( g_ResourceManager->GetLocaleInfo( LOCALE_SMONTHOUSANDSEP, NULL, 0 ) )
                        {
                                    g_ResourceManager->GetLocaleInfo( LOCALE_SMONTHOUSANDSEP, _strGroupSeparator.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
                                    _strGroupSeparator.ReleaseBuffer();
                        }
                        TCHAR cPosCurFormatIndex = _T(’0’);
                        if( g_ResourceManager->GetLocaleInfo( LOCALE_ICURRENCY, NULL, 0 ) )
                                    g_ResourceManager->GetLocaleInfo( LOCALE_ICURRENCY, &cPosCurFormatIndex, sizeof( cPosCurFormatIndex ) );
                        m_nPositiveFormatIndex = _ttoi( & cPosCurFormatIndex );
                        CExtSafeString strNegCurFormatIndex = _T("0");
                        if( g_ResourceManager->GetLocaleInfo( LOCALE_INEGCURR, NULL, 0 ) )
                        {
                                    g_ResourceManager->GetLocaleInfo( LOCALE_INEGCURR, strNegCurFormatIndex.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
                                    strNegCurFormatIndex.ReleaseBuffer();
                        }
                        CExtSafeString strDigitGrouping = _T("0");
                        if( g_ResourceManager->GetLocaleInfo( LOCALE_SMONGROUPING, NULL, 0 ) )
                        {
                                    g_ResourceManager->GetLocaleInfo( LOCALE_SMONGROUPING, strDigitGrouping.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
                                    strDigitGrouping.ReleaseBuffer();
                                    INT nStrLen = INT( strDigitGrouping.GetLength() );
                                    CExtSafeString _strGroup = _T("");
                                    INT nGroup = 0;
                                    if( m_listDigitGrouping.GetCount() > 0 )
                                                m_listDigitGrouping.RemoveAll();
                                    for( INT i = 0; i < nStrLen; i++ )
                                    {
                                                TCHAR ch = strDigitGrouping[i];
                                                if( ch == _T(’;’) )
                                                {
                                                            nGroup = _ttoi( _strGroup );
                                                            m_listDigitGrouping.AddTail( nGroup );
                                                            _strGroup = _T("");
                                                            nGroup = 0;
                                                }
                                                else
                                                            _strGroup = _strGroup + ch;
                                    }
                                    nGroup = _ttoi( _strGroup );
                                    m_listDigitGrouping.AddTail( nGroup );
                        }
                        m_nNegativeFormatIndex = _ttoi( strNegCurFormatIndex );
                        if(                     _strDecimalPoint == _strGroupSeparator
                                    &&        (           _strDecimalPoint == _T(".")
                                    ||           _strDecimalPoint == _T(",")
                                    )
                                    )
                                    _strGroupSeparator = ( _strDecimalPoint == _T(",") ? _T(".") : _T(",") );
                        if(                     _strDecimalPoint == _strGroupSeparator
                                    &&        (           _strDecimalPoint != _T(".")
                                    &&        _strDecimalPoint != _T(",")
                                    )
                                    )
                                    _strDecimalPoint == _T(".");
                        USES_CONVERSION;
                        strCopy = OLE2CT( _bstr );
                        CExtSafeString strTextChange;
                        bool bInsertNegativeSign = ( lfValue < 0 );
                        if( bInsertNegativeSign )
                        {
                                    INT nNegSignPos = strCopy.Find( _T(’-’) );
                                    strCopy.Delete( nNegSignPos );
                        }
                        if( _strDecimalPoint != _T(’.’) )
                        {
                                    INT nPosDot = strCopy.Find( _T(’.’) );
                                    if( nPosDot >= 0 )
                                    {
                                                strCopy.Delete( nPosDot );
                                                strCopy.Insert( nPosDot, _strDecimalPoint );
                                    }
                        }
                        INT nTextLen = INT( strCopy.GetLength() );
                        INT nDecimalSeparatorLen = INT( _strDecimalPoint.GetLength() );
                        INT nPositionDecimalPoint = INT( strCopy.Find( _strDecimalPoint ) );
                        INT nWholeNumber = ( ( nPositionDecimalPoint >= 0 ) ? ( ( nPositionDecimalPoint < m_nMaxWholeDigits ) ? nPositionDecimalPoint : m_nMaxWholeDigits ) : ( ( m_nMaxWholeDigits >= nTextLen ) ?  nTextLen : m_nMaxWholeDigits ) );
                        INT nDecimalPointLen = nDecimalSeparatorLen; // 1
                        INT nCorectTextLen = nWholeNumber + nDecimalPointLen + m_nMaxFractionDigits;
                        nCorectTextLen = ( nCorectTextLen > nTextLen ) ? nTextLen : nCorectTextLen;
                        INT nCountDigitGroups = INT( m_listDigitGrouping.GetCount() );
                        CList < INT, INT > _listPos;
                        bool bLastZiro = ( m_listDigitGrouping.GetAt( m_listDigitGrouping.FindIndex( nCountDigitGroups - 1 ) ) == 0 ) ? true : false;
                        __EXT_DEBUG_GRID_ASSERT( nWholeNumber <= m_nMaxWholeDigits );
                        INT nPos = nWholeNumber;
                        INT i = 0;
                        INT nPreviousCount = -1;
                        for( ; true; )
                        {
                                    INT nCount = m_listDigitGrouping.GetAt(m_listDigitGrouping.FindIndex(i));
                                    if( nCount == 0 && i < ( nCountDigitGroups - 1 ) )
                                                break;
                                    if( nCount == 0 && i == ( nCountDigitGroups - 1 ) )
                                    {
                                                __EXT_DEBUG_GRID_ASSERT( nPreviousCount != -1 );
                                                nCount = nPreviousCount;
                                    }
                                    nPos -= nCount;
                                    if( nPos > 0 )
                                                _listPos.AddHead( nPos - 1 );
                                    else
                                                break;
                                    if( i == ( nCountDigitGroups - 1 ) && ! bLastZiro )
                                                break;
                                    if( i < ( nCountDigitGroups - 1 ) )
                                                i ++;
                                    nPreviousCount = nCount;
                        }
                        INT nCurDigitPos = 0;
                        INT nPosCount = INT( _listPos.GetCount() );
                        bool bCanPastGroupSep = ( nPosCount > 0 );
                        for( i = 0; i < nCorectTextLen; i++ )
                        {
                                    TCHAR _tchr = strCopy[i];
                                    strTextChange += _tchr;
                                    bool bInsertSign = false;
                                    INT nPosCur = 0;
                                    if( bCanPastGroupSep )
                                                nPosCur = _listPos.GetAt( _listPos.FindIndex( nCurDigitPos ) );
                                    if(                     ( i <= nWholeNumber )
                                                &&        ( i != ( nCorectTextLen - 1 ) )
                                                &&        ( i == nPosCur )
                                                &&        bCanPastGroupSep
                                                )
                                    {
                                                strTextChange += _strGroupSeparator;
                                                bInsertSign = true;
                                                if( nCurDigitPos < ( nPosCount - 1 ) )
                                                            nCurDigitPos ++;
                                                else
                                                            bCanPastGroupSep = false;
                                    }
                                    if( i == ( nWholeNumber - 1 ) && ( nPositionDecimalPoint == -1 ) && ( i != nCorectTextLen - 1 ) )
                                                strTextChange += _strDecimalPoint;
                        }
                        CExtSafeString _strSignBefore = _T("");
                        CExtSafeString _strSignAfter = _T("");
                        {
                                    __EXT_DEBUG_GRID_ASSERT_VALID( this );
                                    CExtSafeString strBefore = _T("");
                                    CExtSafeString strAfter = _T("");
                                    if( bInsertNegativeSign )
                                    {
                                                switch( m_nNegativeFormatIndex )
                                                {
                                                case 0:
                                                            strBefore = _T("(") + _strCurrencySymbol;
                                                            strAfter = _T(")");
                                                            break;
                                                case 1:
                                                            strBefore = _strNegativeSign + _strCurrencySymbol;
                                                            break;
                                                case 2:
                                                            strBefore = _strCurrencySymbol + _strNegativeSign;
                                                            break;
                                                case 3:
                                                            strBefore = _strCurrencySymbol;
                                                            strAfter = _strNegativeSign;
                                                            break;
                                                case 4:
                                                            strBefore = _T("(");
                                                            strAfter = _strCurrencySymbol + _T(")");
                                                            break;
                                                case 5:
                                                            strBefore = _strNegativeSign;
                                                            strAfter = _strCurrencySymbol;
                                                            break;
                                                case 6:
                                                            strAfter = _strNegativeSign + _strCurrencySymbol;
                                                            break;
                                                case 7:
                                                            strAfter = _strCurrencySymbol + _strNegativeSign;
                                                            break;
                                                case 8:
                                                            strBefore = _strNegativeSign;
                                                            strAfter = _T(" ") + _strCurrencySymbol;
                                                            break;
                                                case 9:
                                                            strBefore = _strNegativeSign + _strCurrencySymbol + _T(" ");
                                                            break;
                                                case 10:
                                                            strAfter = _T(" ") + _strCurrencySymbol + _strNegativeSign;
                                                            break;
                                                case 11:
                                                            strBefore = _strCurrencySymbol + _T(" ");
                                                            strAfter = _strNegativeSign;
                                                            break;
                                                case 12:
                                                            strBefore = _strCurrencySymbol + _T(" ") + _strNegativeSign;
                                                            break;
                                                case 13:
                                                            strAfter = _strNegativeSign + _T(" ") + _strCurrencySymbol;
                                                            break;
                                                case 14:
                                                            strBefore = _T("(") + _strCurrencySymbol + _T(" ");
                                                            strAfter = _T(")");
                                                            break;
                                                case 15:
                                                            strBefore = _T("(");
                                                            strAfter = _T(" ") + _strCurrencySymbol + _T(")");
                                                            break;
                                                }
                                    }
                                    else
                                    {
                                                switch( m_nPositiveFormatIndex )
                                                {
                                                case 0:
                                                            strBefore = _strCurrencySymbol;
                                                            break;
                                                case 1:
                                                            strAfter = _strCurrencySymbol;
                                                            break;
                                                case 2:
                                                            strBefore = _strCurrencySymbol + _T(" ");
                                                            break;
                                                case 3:
                                                            strAfter = _T(" ") + _strCurrencySymbol;
                                                            break;
                                                }
                                    }
                                    _strSignBefore = strBefore;
                                    _strSignAfter = strAfter;
                        }
                        if( _strSignAfter.GetLength() > 0 )
                                    strTextChange.Insert( strTextChange.GetLength(), _strSignAfter );
                        if( _strSignBefore.GetLength() > 0 )
                                    strTextChange.Insert( 0, _strSignBefore );
                        strCopy = strTextChange;
            }
            break;
            } // switch( eim )
            if( _bstr != NULL )
                        ::SysFreeString( _bstr );
}