User forums > General (but related to Code::Blocks)
Compile errors
sethjackson:
I'm trying to convert text to HTML.
Here is the code.
m_pTextCtrl is a wxTextCtrl.
--- Code: ---wxString MainFrame::TextToHTML()
{
const wxString sOO = _T("00");
const wxString s8O = _T("80");
const wxString sFF = _T("FF");
wxString htmlString;
htmlString << _T("<html><head><title></title></head><body><tt>");
long max = m_pTextCtrl->GetLastPosition();
wxTextAttr style;
wxTextAttr oldStyle;
wxChar ch;
for(long pos = 0; pos < max; pos++)
{
m_pTextCtrl->GetStyle(pos, style);
if(style != oldStyle)
{
if(pos > 0)
{
htmlString << _T("</font>");
}
wxString sR, sG, sB;
wxColour colour = style.GetTextColour();
sR.Printf(_T("%02X"), colour.Red());
sG.Printf(_T("%02X"), colour.Green());
sB.Printf(_T("%02X"), colour.Blue());
htmlString << _T("<font color = \"#") << sR << sG << sB << _T("\">"); ;
}
if (m_pTextCtrl->GetInsertionPoint() == m_pTextCtrl->GetLastPosition())
{
ch = _T('\0');
}
else
{
ch = m_pTextCtrl->GetValue[m_pTextCtrl->GetInsertionPoint()];
}
switch(ch)
{
case _T('\n'):
{
htmlString << _T("\n<br>");
}
break;
case _T('<'):
{
htmlString << _T("<");
}
break;
case _T('&'):
{
htmlString << _T("&");
}
break;
case _T(' '):
{
htmlString << _T(" ");
}
break;
default:
{
htmlString << ch;
}
break;
}
oldStyle = style;
}
htmlString << _T("</font></tt></body></html>");
return htmlString;
}
--- End code ---
I get build errors though...
--- Code: ---Switching to target: default
Compiling: main.cpp
main.cpp: In member function `wxString MainFrame::TextToHTML()':
main.cpp:214: error: no match for 'operator!=' in 'style != oldStyle'
C:/wxWidgets-2.6.2/include/wx/string.h:1428: note: candidates are: bool operator!=(const wxString&, const wxString&)
C:/wxWidgets-2.6.2/include/wx/string.h:1430: note: bool operator!=(const wxString&, const wxChar*)
C:/wxWidgets-2.6.2/include/wx/string.h:1432: note: bool operator!=(const wxChar*, const wxString&)
C:/wxWidgets-2.6.2/include/wx/string.h:1473: note: bool operator!=(const wxString&, const wxCharBuffer&)
C:/wxWidgets-2.6.2/include/wx/string.h:1475: note: bool operator!=(const wxCharBuffer&, const wxString&)
C:/wxWidgets-2.6.2/include/wx/string.h:1496: note: bool operator!=(wxChar, const wxString&)
C:/wxWidgets-2.6.2/include/wx/string.h:1497: note: bool operator!=(const wxString&, wxChar)
C:/wxWidgets-2.6.2/include/wx/longlong.h:917: note: bool operator!=(long int, const wxLongLong&)
C:/wxWidgets-2.6.2/include/wx/longlong.h:930: note: bool operator!=(long unsigned int, const wxULongLong&)
C:/Program Files/CodeBlocks/include/objbase.h:82: note: BOOL operator!=(const GUID&, const GUID&)
main.cpp:239: error: invalid types `<unknown type>[long int]' for array subscript
Process terminated with status 1 (0 minutes, 11 seconds)
--- End code ---
What am I doing wrong?
Ceniza:
It seems like there's no operator != overloaded for wxTextAttr, so if(style != oldStyle) cannot be compiled.
sethjackson:
but what about this.
--- Code: ---error: invalid types `<unknown type>[long int]' for array subscript
--- End code ---
mandrav:
--- Quote from: sethjackson on November 07, 2005, 02:24:07 pm ---but what about this.
--- Code: ---error: invalid types `<unknown type>[long int]' for array subscript
--- End code ---
--- End quote ---
Change ch = m_pTextCtrl->GetValue[m_pTextCtrl->GetInsertionPoint()];
to ch = m_pTextCtrl->GetValue()[m_pTextCtrl->GetInsertionPoint()];
(notice the parentheses)
sethjackson:
I tried that. I still get errors
--- Code: ---main.cpp:235: error: ambiguous overload for 'operator[]' in '*(((MainFrame*)this)->MainFrame::m_pTextCtrl->wxTextCtrl::_vptr$wxObject + 768u)()[(*(((MainFrame*)this)->MainFrame::m_pTextCtrl->wxTextCtrl::_vptr$wxObject + 936u))(((MainFrame*)this)->MainFrame::m_pTextCtrl)]'
main.cpp:235: note: candidates are: operator[](const wxChar*, int) <built-in>
C:/wxWidgets-2.6.2/include/wx/string.h:767: note: wxChar& wxString::operator[](int)
C:/wxWidgets-2.6.2/include/wx/string.h:769: note: wxChar& wxString::operator[](size_t)
Process terminated with status 1 (0 minutes, 13 seconds)
--- End code ---
I got
--- Code: ---m_pTextCtrl->GetValue[m_pTextCtrl->GetInsertionPoint()];
--- End code ---
From the wxWidgets manual so it should work I thought....
Navigation
[0] Message Index
[#] Next page
Go to full version