这段代码
CString CLayerInfo::SetQueryCondition(CString bstrWhere,CString bstrNewString)
{
bstrWhere=bstrWhere+bstrNewString;
return bstrWhere;
}
当我调用这个函数时,bstrNewString的值可以传过来,bstrWhere是空,调用它之后应该返回一个bstrWher的值才对阿,但是我的返回值却是空的,这是为什么阿?
我做了几次尝试,如果将函数中的CString加操作换成bstrWhere=bstrNewString+“aa”,那返回的结果只有aa,这是什么原因阿?

解决方案 »

  1.   

    只能说明你bstrNewString是空的。
      

  2.   

    肯定是空的,你在里面设断点DEBUG一下,肯定是空的
      

  3.   

    CString CLayerInfo::SetQueryCondition(CString bstrWhere,CString bstrNewString)
    {
    AfxMessageBox(bstrNewString); // 检查一下看看吧!
    bstrWhere=bstrWhere+bstrNewString;
    AfxMessageBox(bstrWhere);
    return bstrWhere;
    }
      

  4.   

    这样定义函数:通过参数把结果返回
    void CLayerInfo::SetQueryCondition(CString &bstrWhere,CString bstrNewString)
    {
    bstrWhere=bstrWhere+bstrNewString;
    }调用的时候:
    SetQueryCondition("hello","you");
      

  5.   

    CString CLayerInfo::SetFilterCondition(CString bstrWhere, CString bstrNewString)
    {
    bstrWhere=bstrWhere+bstrNewString;
    return bstrWhere;
    }
    void CLayerInfo::OnSelchangeComboFieldname() 
    {
    // TODO: Add your control notification handler code here
    long lCnt,llCnt,H=1;
    CString FieldName; lCnt=m_strFieldName.GetCurSel();
    if(lCnt<0||m_strFieldName.GetCount()==0)
    return;
    llCnt=m_strFieldName.GetLBTextLen(lCnt);
    m_strFieldName.GetLBText(lCnt,FieldName.GetBuffer(llCnt));

    m_strCondition=SetFilterCondition(m_strCondition,FieldName); m_strFieldValue.ResetContent(); UpdateData(FALSE);
    return;
    }
    m_strCondition是绑定的EDIT的控件变量,是CString类型的。m_strFieldName是绑定的combobox的控制变量,就是这个SetFilterCondition调用,之后m_strCondition仍然是空
      

  6.   

    初始时m_strCondition是空的,FieldName是在combobox中选取的一项