帮我在不同对话框的两个控制变量之间传递字符串 [英] Help me passing string between two control variables of different dialogs
问题描述
伙计们,m_strMessage是我父类的一个名为CsocketDlg的控件变量。 m_sFrameLB是我的无模式MFC类的控件变量,名为CSetThresholdFineDfLB。现在通过检查条件,我想将存储在m_sFrameLB中的字符串传递给m_strMessage。我应该在我的孩子无模式对话框的按钮下编写此代码。这是我的代码:
Guys, m_strMessage is a control variable of my parent class named CsocketDlg. And m_sFrameLB is a control variable of my modeless MFC class named CSetThresholdFineDfLB. Now by checking a conditon I wanna pass a string that is stored in m_sFrameLB to m_strMessage. i should write this code under a buttonclick of my child modeless dialog. Here is my code:
void CSetThresholdFineDfLB::OnClickedIdapply()
{
// TODO: Add your control notification handler code here
//CString commandcodelb,framelb;
//int tvlb;
// commandcodelb = m_sCommandCode;
//tvlb = m_iThresholdValue;
if(m_iThresholdValue==0)
{
SetDlgItemText(IDC_FineDfLBFrame, _T("C901A3"));
CsocketDlg.m_strMessage = m_sFrameLB;
}
else
SetDlgItemText(IDC_FineDfLBFrame, _T("INVALID TV"));
// UpdateData(FALSE);
}
当我写这行CsocketDlg.m_strMessage = m_sFrameLB;时,我收到错误:
a non static成员引用必须与特定对象相关。请帮我。我还在child.cpp文件中包含父类头文件。
When i wrote this line "CsocketDlg.m_strMessage = m_sFrameLB;", I got the error:
a non static member reference must be relative to a specific object. Please help me. Also I included parent class header file in child.cpp file.
推荐答案
请参阅我对该问题的评论。你似乎不明白哪些类是什么,为什么要使用它们。我可以回答,但我不认为它可以帮助你,除非你退后一步,至少学习一下课程及其实例,以及静态。
Please see my comment to the question. It's quite appear that you don't understand what classes are and why do you use them. I can answer, but I don't think it can help you unless you step back and learn at least a bit about classes and their instances, and also about "static".
// It cannot compile because m_strMessage is non-static. It belongs to instance, not class:
//CsocketDlg.m_strMessage = m_sFrameLB;
// you need some instance:
CsocketDlg myDlg = // whatever
myDlg.m_strMessage = //... will compile
// of
CsocketDlg * myDlgPointer = // whatever
myDlgPointer -> m_strMessage = //... will compile
但您还需要足够的访问权限。或者,你可以有 static
字段,可以通过课程访问 - 不推荐!解释原因还为时过早;首先,你需要了解课程。此刻,你没有任何线索。别担心,你很快就会学到它。就这么做。
But you also need enough access to this member. Alternatively, you could have static
field, which could be accessed via the class — not recommended! It's too early to explain why; first, you need to learn about classes. At this moment, you have no clue. Don't worry, you will learn it soon. Just do it.
这篇关于帮我在不同对话框的两个控制变量之间传递字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!