xml文件:ftp_file_list_item.xml
<?xml version="1.0" encoding="UTF-8"?>
<Window>
<HorizontalLayout height="20" width="700">
<ListContainerItemEx name="btnFileChoose" bkimage="file='png/ftplist/deficon.png' dest='11,1,24,18'" height="20" width="700" bordersize="1" bordercolor="#FFFFFFFF" selectedbordercolor="#FFAAD9FF" > <!-- bordersize="1" focusbordercolor="#FFAAD9FF"-->
</ListContainerItemEx>
<Label name="fileicon" width="30" textpadding="10,0,0,0" align="left" align="vcenter" height="20" />
<Label name="editfilename" text="名称" textpadding="10,0,0,0" align="left" endellipsis="true" align="vcenter" width="162" height="20" />
<Label name="filetype" text="类型" textpadding="10,0,0,0" align="left" align="vcenter" width="121" height="20" />
<Label name="filedate" text="日期" textpadding="10,0,0,0" align="left" align="vcenter" width="213" height="20" />
<Label name="filesize" text="大小" textpadding="10,0,0,0" align="left" align="vcenter" width="160" height="20" />
<RichEditEx name="newnameedit" selectedtextcolor="#FFFFFFFF" textpadding="10,4,2,0" align="left" align="vcenter" float="true" pos="30,0,0,0" hscrollbar="true" autohscroll="true" visible="false" bordersize="1" bordercolor="#FF000000" multiline="false" width="162" height="20" />
</HorizontalLayout>
</Window>
C++代码:
bool CFileDirList::AddItem(FtpDirFileInfo info)
{
CHorizontalLayoutUI* pCon = NULL;
string_t str = L"xml/ftp_file_list_item.xml";
//CDialogBuilder m_dlgBuilder;
if( !m_dlgBuilder.GetMarkup()->IsValid() )
{
pCon = static_cast<CHorizontalLayoutUI*>(m_dlgBuilder.Create(str.c_str(), (UINT)0, this, GetManager()));
}
else
{
pCon = static_cast<CHorizontalLayoutUI*>(m_dlgBuilder.Create( this, GetManager()));
}
if( pCon == NULL)
return false;
//CListTextElementExUI *pElement = static_cast<CListTextElementExUI*>(GetManager()->FindSubControlByName( pCon, _T("btnFileChoose") ));
CListContainerItemExUI* pElement = static_cast<CListContainerItemExUI*>(GetManager()->FindSubControlByName( pCon, _T("btnFileChoose") ));
if (pElement == NULL)
{
return false;
}
bool ret = false;
CLabelUI* pIcon = static_cast<CLabelUI*>(GetManager()->FindSubControlByName(pCon, _T("fileicon")));
CLabelUI* pName = static_cast<CLabelUI*>(GetManager()->FindSubControlByName(pCon, _T("editfilename")));
CLabelUI* pType = static_cast<CLabelUI*>(GetManager()->FindSubControlByName(pCon, _T("filetype")));
CLabelUI* pTime = static_cast<CLabelUI*>(GetManager()->FindSubControlByName(pCon, _T("filedate")));
CLabelUI* pSize = static_cast<CLabelUI*>(GetManager()->FindSubControlByName(pCon, _T("filesize")));
CRichEditExUI *pEdit = static_cast<CRichEditExUI*>(GetManager()->FindSubControlByName(pCon, _T("newnameedit")));
if (pIcon == NULL || pName == NULL || pType == NULL || pTime == NULL || pSize == NULL || pEdit == NULL)
{
TRY_DELETE(pCon);
TRY_DELETE(pElement);
return false;
}
pElement->Add(pIcon);
pElement->Add(pName);
pElement->Add(pEdit);
pElement->Add(pType);
pElement->Add(pTime);
pElement->Add(pSize);
//需要增加增加一层, 如果直接Add pCon Remove 时会将remove 释放, 由于pCon只有一个实例, delete 第一个item时就会被释放,而且会有0xC0000005 异常
ret = m_pList->Add(pElement);
}
这种方式在 ContainerUI::RemoveAll() 或者 Remove() 正常; 但是如果这样写:
<?xml version="1.0" encoding="UTF-8"?>
<Window>
<HorizontalLayout height="20" width="700">
<ListContainerItemEx name="btnFileChoose" bkimage="file='png/ftplist/deficon.png' dest='11,1,24,18'"
height="20" width="700" bordersize="1" bordercolor="#FFFFFFFF" selectedbordercolor="#FFAAD9FF" >
<!-- bordersize="1" focusbordercolor="#FFAAD9FF"-->
<Label name="fileicon" width="30" textpadding="10,0,0,0" align="left" align="vcenter" height="20" />
<Label name="editfilename" text="名称" textpadding="10,0,0,0" align="left" endellipsis="true" align="vcenter" width="162" height="20" />
<Label name="filetype" text="类型" textpadding="10,0,0,0" align="left" align="vcenter" width="121" height="20" />
<Label name="filedate" text="日期" textpadding="10,0,0,0" align="left" align="vcenter" width="213" height="20" />
<Label name="filesize" text="大小" textpadding="10,0,0,0" align="left" align="vcenter" width="160" height="20" />
<RichEditEx name="newnameedit" selectedtextcolor="#FFFFFFFF" textpadding="10,4,2,0" align="left" align="vcenter" float="true" pos="30,0,0,0" hscrollbar="true" autohscroll="true" visible="false" bordersize="1" bordercolor="#FF000000" multiline="false" width="162" height="20" />
</ListContainerItemEx>
</HorizontalLayout>
</Window>
当List 执行RemoveAll(); 或者Remove()时,容器下的ListContainerItemEx相当于ListContainerElement在 Remove时 m_items[], ListContainerItemEx的items 为12 这样释放权限问题
因为本身改容器就存在6个Control, 程序代码又添加了6个Control; 释放就出现了问题;
第一种情况下正常,调试信息如下:
这样释放就正常;
重复遇到两次,第二次遇到此问题,留笔记录!