duilib 动态添加 提前写好xml

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; 释放就出现了问题;

第一种情况下正常,调试信息如下:

这样释放就正常;

重复遇到两次,第二次遇到此问题,留笔记录!

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值