HELP!MFC, how to operate another class variables?

kanch96

Solid State Member
Messages
18
Location
China
Thank you have time to see this post

MFC, how to operate another class variables?

It can release success but while I run the program Trigger OnBnClickedOk() function the problem arise it says:
“Run-Time Check Failure #3 - The variable 'dlg' is being used without being initialized.”

The function of the source code is as follows:



Code:
void AddNewItemDlg::OnBnClickedOk()
{
	CICDlg *dlg;
//Get User's data
	GetDlgItem(ADDNEWITEM_ID)->GetWindowTextA(dlg->Value[0]);
	GetDlgItem(ADDNEWITEM_PASSWORD)->GetWindowTextA(dlg->Value[1]);
	GetDlgItem(ADDNEWITEM_PIECE)->GetWindowTextA(dlg->Value[2]);
	GetDlgItem(ADDNEWITEM_ABOUT)->GetWindowTextA(dlg->Value[3]);

	MessageBox(dlg->Value[0]+"\n"+dlg->Value[1]+"\n"+dlg->Value[2]+"\n"+dlg->Value[3],"C2p容错机制");
	CDialogEx::OnOK();
}
notes: CICDlg is another class
this program is based on MFC Dialog CICDlg is father dialog,Dialog box(I mean AddNewItemDlg) is a modal dialog box displayed

I don't know where I did wrong,I need your help .
 
sorry,I forgot to tell you what the language is
it's C++(Based on MFC)
 
Just a guess, but it looks like you're just declaring the variable and not actually creating any memory space for it. You need to allocate dynamic memory using the class's constructor before using any member variables.
 
you mean the variable "dlg"?
Should be written following ?



Code:
void AddNewItemDlg::OnBnClickedOk()
{
	[COLOR="Red"]CICDlg *dlg = new CICDlg;[/COLOR]
//Get User's data
	GetDlgItem(ADDNEWITEM_ID)->GetWindowTextA(dlg->Value[0]);
	GetDlgItem(ADDNEWITEM_PASSWORD)->GetWindowTextA(dlg->Value[1]);
	GetDlgItem(ADDNEWITEM_PIECE)->GetWindowTextA(dlg->Value[2]);
	GetDlgItem(ADDNEWITEM_ABOUT)->GetWindowTextA(dlg->Value[3]);

	MessageBox(dlg->Value[0]+"\n"+dlg->Value[1]+"\n"+dlg->Value[2]+"\n"+dlg->Value[3],"C2p容错机制");

	CDialogEx::OnOK();
}
 
Yes, I mean the variable "dlg".

You should look at the library's documentation to see how to properly initialize an instance of the variable.
 
Back
Top Bottom