changing text of listCtrl-header - part two
-
Got good help last week for changing text of listCtrl-header and I thougth, my problem is solved. I've the following code:
void koarkstewView::alterheadercontent() { LVCOLUMN lvc; CString titel; CListCtrl &listCtrl = GetListCtrl(); koarkstewDoc* pDoc = GetDocument(); karkst *karkstanz; karkstanz = pDoc->karkstanz; pDoc->SetTitle("KAR->KST"); int i = 3; if (karkstanz->wdfirst()) do { i++; titel = karkstanz->wdgetkarnr() + "\n"; titel = titel + gettitel(0, karkstanz->wdgetdatenart(), karkstanz->wdgetvon(), karkstanz->wdgetbis()); listCtrl.GetColumn(i, &lvc); lvc.pszText = titel.GetBuffer(0); titel.ReleaseBuffer(); listCtrl.SetColumn(i, &lvc); } while(karkstanz->wdnext()); }
Works fine - but only in debug-mode!! In release-mode, the text doesn't change:mad: But how to debug the code, if it work's in debug-mode:confused: Any proposals?? Thanks, Gerhard -
Got good help last week for changing text of listCtrl-header and I thougth, my problem is solved. I've the following code:
void koarkstewView::alterheadercontent() { LVCOLUMN lvc; CString titel; CListCtrl &listCtrl = GetListCtrl(); koarkstewDoc* pDoc = GetDocument(); karkst *karkstanz; karkstanz = pDoc->karkstanz; pDoc->SetTitle("KAR->KST"); int i = 3; if (karkstanz->wdfirst()) do { i++; titel = karkstanz->wdgetkarnr() + "\n"; titel = titel + gettitel(0, karkstanz->wdgetdatenart(), karkstanz->wdgetvon(), karkstanz->wdgetbis()); listCtrl.GetColumn(i, &lvc); lvc.pszText = titel.GetBuffer(0); titel.ReleaseBuffer(); listCtrl.SetColumn(i, &lvc); } while(karkstanz->wdnext()); }
Works fine - but only in debug-mode!! In release-mode, the text doesn't change:mad: But how to debug the code, if it work's in debug-mode:confused: Any proposals?? Thanks, Gerhardensger wrote:
listCtrl.GetColumn(i, &lvc); lvc.pszText = titel.GetBuffer(0); titel.ReleaseBuffer(); listCtrl.SetColumn(i, &lvc);
Modify this to,
LVCOLUMN lvc= {0};
listCtrl.GetColumn(i, &lvc);
lvc.mask = LVCF_TEXT ;
lvc.pszText = titel.GetBuffer(0);
titel.ReleaseBuffer();
listCtrl.SetColumn(i, &lvc);Read this[^] article for better understanding of difference betn release and debug configuration.
Prasad Notifier using ATL | Operator new[],delete[][^]
-
ensger wrote:
listCtrl.GetColumn(i, &lvc); lvc.pszText = titel.GetBuffer(0); titel.ReleaseBuffer(); listCtrl.SetColumn(i, &lvc);
Modify this to,
LVCOLUMN lvc= {0};
listCtrl.GetColumn(i, &lvc);
lvc.mask = LVCF_TEXT ;
lvc.pszText = titel.GetBuffer(0);
titel.ReleaseBuffer();
listCtrl.SetColumn(i, &lvc);Read this[^] article for better understanding of difference betn release and debug configuration.
Prasad Notifier using ATL | Operator new[],delete[][^]
-
Many thanks, it work's. And thank's for the link. I'll have to read cause I didn't recognice till yet, that programs that work in debug-mode maybe will not work in release-mode.
ensger wrote:
didn't recognice till yet, that programs that work in debug-mode maybe will not work in release-mode
On broader level, in debug mode, lots of things would be taken care of. One of them is variable initialization. In your case though, you did miss to mention mask. And its always good practice to initialize variables.
Prasad Notifier using ATL | Operator new[],delete[][^]
-
Got good help last week for changing text of listCtrl-header and I thougth, my problem is solved. I've the following code:
void koarkstewView::alterheadercontent() { LVCOLUMN lvc; CString titel; CListCtrl &listCtrl = GetListCtrl(); koarkstewDoc* pDoc = GetDocument(); karkst *karkstanz; karkstanz = pDoc->karkstanz; pDoc->SetTitle("KAR->KST"); int i = 3; if (karkstanz->wdfirst()) do { i++; titel = karkstanz->wdgetkarnr() + "\n"; titel = titel + gettitel(0, karkstanz->wdgetdatenart(), karkstanz->wdgetvon(), karkstanz->wdgetbis()); listCtrl.GetColumn(i, &lvc); lvc.pszText = titel.GetBuffer(0); titel.ReleaseBuffer(); listCtrl.SetColumn(i, &lvc); } while(karkstanz->wdnext()); }
Works fine - but only in debug-mode!! In release-mode, the text doesn't change:mad: But how to debug the code, if it work's in debug-mode:confused: Any proposals?? Thanks, Gerhardensger wrote:
lvc.pszText = titel.GetBuffer(0);
Why are you calling
GetBuffer()
unnecessarily? I don't see that you are modifyingtitel
.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
ensger wrote:
lvc.pszText = titel.GetBuffer(0);
Why are you calling
GetBuffer()
unnecessarily? I don't see that you are modifyingtitel
.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Because lvc.pszText = titel; results in an error-message like 'no operator defined, that accepts a right-sided operator of type 'class CString''. I didn't even know the existence of 'GetBuffer()' till last week - but it works ;)
ensger wrote:
...but it works
Of course it does, but
GetBuffer()
exposes the underlyingchar*
object to possible (unwanted) changes. Try:lvc.pszText = (LPTSTR) ((LPCTSTR) titel);
Now
titel
cannot be accidentally changed.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
ensger wrote:
...but it works
Of course it does, but
GetBuffer()
exposes the underlyingchar*
object to possible (unwanted) changes. Try:lvc.pszText = (LPTSTR) ((LPCTSTR) titel);
Now
titel
cannot be accidentally changed.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb