CListCtrl: Do text subitems require dynamic allocations and deletions?

When I create subitems for a list control, do I need to dynamically allocate 
memory for text items, then free that memory on item destruction? Or does 
the CListCtrl automatically make a copy of any string I assign to it for 
subitems and automatically free the memory?

For example, would the following be valid? does the ListView_SetItem() make 
a copy of the text assigned to lvi.pszText?

==== sample below ======

LVITEM lvi;
lvi.mask = LVIF_TEXT;

CString strName="Some Name";
CString strStatus="Some Status";

for ( i = 0; i < x; i++ )
{
 m_ctrlPackageList.InsertItem( i, strName );

 lvi.iItem = i;
 lvi.iSubItem = 1;
 lvi.pszText = strStatus;
 lvi.cchTextMax = strStatus.GetLength();

 ListView_SetItem( m_ctrlPackageList, &lvi );
}

0
mfindlay (14)
6/10/2005 11:03:39 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
607 Views

Similar Articles

[PageSpeed] 54

Hi mark,

>When I create subitems for a list control, do I need to dynamically 
allocate 
>memory for text items, then free that memory on item destruction?

You don't need to dynamically allocate memory for text items of a listview 
control, the general convention is to use auto string objects(local 
varibles which created on stack just as your code snippet).The CListCtrl 
will make a copy of the text item's string for its own use and manage it 
automatically.


Thanks!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ��C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn 

This posting is provided "AS IS" with no warranties, and confers no rights.

0
v-garych (605)
6/11/2005 3:55:26 AM
Hi Mark,

I am reviewing this issue thread. Do you have any more questions on it? If 
there is any unclear, please feel free to reply here and we are here to 
support you at your convenience.

Thanks very much for participating the community.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! �C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn 

This posting is provided "AS IS" with no warranties, and confers no rights.

0
yhhuang (111)
6/15/2005 2:44:26 AM
Reply:

Similar Artilces: