建立了一个结构体,想用它保存列表控件List Control中的内容,然后在下拉列表控件Combo Box中读取结构体中一个变量的值,也就是列表控件中对应的一列。编译过了,但是运行保存的时候,提示:“ox5f47720c”指令引用的“oxccccccd4”内存,该内存不能为“read”。不知道原因,把代码贴出来,请大家帮忙看看://头文件中定义结构体
public:
typedef struct PartAnalysis
{
CString PartID;
CString PartName;
CString GivenName;
CString AF;
CString Type;
}ProductInfo;
ProductInfo *productinfo;//实现文件中,把列表控件内容保存到结构体中,列表控件相关变量m_listPA
void CTestDlg::OnButtonPaSave()
{
int nItemCount=m_listPA.GetItemCount();
for(int i=0;i<nItemCount;i++)
{
productinfo->PartID = m_listPA.GetItemText(i,0);
productinfo->PartName = m_listPA.GetItemText(i,1);
productinfo->GivenName = m_listPA.GetItemText(i,2);
productinfo->AF = m_listPA.GetItemText(i,3);
productinfo->Type = m_listPA.GetItemText(i,4);
}
//向下拉列表中添加GivenName这一列,下拉列表关联变量m_cmbASG_PS
m_cmbASG_PS.AddString(productinfo->GivenName);}
public:
typedef struct PartAnalysis
{
CString PartID;
CString PartName;
CString GivenName;
CString AF;
CString Type;
}ProductInfo;
ProductInfo *productinfo;//实现文件中,把列表控件内容保存到结构体中,列表控件相关变量m_listPA
void CTestDlg::OnButtonPaSave()
{
int nItemCount=m_listPA.GetItemCount();
for(int i=0;i<nItemCount;i++)
{
productinfo->PartID = m_listPA.GetItemText(i,0);
productinfo->PartName = m_listPA.GetItemText(i,1);
productinfo->GivenName = m_listPA.GetItemText(i,2);
productinfo->AF = m_listPA.GetItemText(i,3);
productinfo->Type = m_listPA.GetItemText(i,4);
}
//向下拉列表中添加GivenName这一列,下拉列表关联变量m_cmbASG_PS
m_cmbASG_PS.AddString(productinfo->GivenName);}
解决方案 »
- 数据结构字符串操作Replace函数??
- 如何立即结束一个正在工作的线程?
- 请教三叉数排序算法的C实现
- 怎样用代码实现Edit Box的Visible属性为FALSE?
- 如何读取局域网内计算机的注册表信息和复制文件?
- 请教如何像很多应用程序那样在一个TreeView里面显示我的电脑->各驱动器这样的Tree?
- microsoft 的bug ,问题很复杂,MFC编写的ActiveX控件为什么在Web页面上总是浮现为最上层,其他页面无法覆盖
- 一个诡异的问题
- 有VC做PCI虚拟示波器的源码示例?
- 请问:cs.style |= WS_HSCROLL|WSCROLL是什么意思?
- UpdateResource 求改进
- 找工作中……每天散100分(今天散200分,等找到工作再多散分,以后就不再每天发了)
productinfo = new ProductInfo [nItemCount];
for(int i=0;i<nItemCount;i++)
{
productinfo[i].PartID = m_listPA.GetItemText(i,0);
prproductinfo[i].PartName = m_listPA.GetItemText(i,1);
productinfo[i].GivenName = m_listPA.GetItemText(i,2);
productinfo[i].AF = m_listPA.GetItemText(i,3);
productinfo[i].Type = m_listPA.GetItemText(i,4);m_cmbASG_PS.AddString(productinfo[i].GivenName);}
delete [] productinfo ;
ok,但是还有个问题,添加到下拉列表中的项有重复,怎么删除重复的啊,
比如列表那一列里面是P1,P2,P2,P3,P3,P3,P4,P5,P5,P6,
用上面的代码后,这些都加进去了,我只希望显示P1,P2,P3,P4,P5,P6,去掉重复的项,怎么操作啊?再谢!
把代码中的m_cmbASG_PS.AddString(productinfo[i].GivenName);
替换成:
int num = m_cmbASG_PS.GetCount();
CString str;
int j=0;
for(j=0; j<num; j++)
{
GetLBText(j,str);
if(!strcmp(str,productinfo[i].GivenName))
break;
}if(j>=num)
m_cmbASG_PS.AddString(productinfo[i].GivenName);