Simply put I wish for text entered in one edit box to then appear in another edit box. I have created a MFC dialog and read many tutorials, but I'm still stuck.

Here is my current DDX function:

void Ctextentry23Dlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Text(pDX, IDC_EDIT1, name);
    DDV_MaxChars(pDX, name, 20);
    DDX_Text(pDX, IDC_EDIT2, name2);
}

I tried adding the line

pDX->m_bSaveAndValidate(FALSE);

but this results in "error C2064: term does not evaluate to a function taking 1 arguments"

I was able to get it work by clicking a button by adding the event handler with the following:

void Ctextentry23Dlg::OnBnClickedButton1()
{
    // TODO: Add your control notification handler code here
    UpdateData(TRUE);
    name2 = name;
    UpdateData(FALSE);
    mywork.mystring = name2;    
}

But I'd like to get this to work without pushing a button.

Thank you!

From the looks of this line:

pDX->m_bSaveAndValidate(FALSE);

It seems to me that you're trying to use a boolean member variable as a function, which is why you're getting that particular error.

I'm pretty certain if you search for the definition of m_bSaveAndValidate it will be declared as a boolean variable NOT as a function which takes a boolean as a parameter.
i.e.

bool m_bSaveAndValidate;

So the reason you are getting that error is because you are trying to use a variable as a function.

If the boolean flag is a public member/property of the class pointed to by pDX, then you should be able to set it directly like this:

pDX->m_bSaveAndValidate = false;

Otherwise, if m_bSaveAndValidate is a private or protected member of whatever class is pointed to by pDX, you will have to use a public function to get or set the value of the flag. If there are currently no public functions in the class which get or set the value of the flag, then you will have to add them to the class yourself.
e.g. in your header:

class YourClass : public WhateverItsDerivedFrom
{
	private: // or it might be under protected!
		bool m_bSaveAndValidate;
		// Other private member variables/functions here

	public:
		// constructor, destructor and other public member variables and functions here
		
		// Accessor functions to get and set the flag
		void SetSaveAndValidate(bool bState){m_bSaveAndValidate = bState;}
		bool GetSaveAndValidate(){return m_bSaveAndValidate;}
};

That way you can call your 'set' function for the flag in your code like this:

pDX->SetSaveAndValidate(false);

Now I'm not sure whether or not that will help with what you want to do, but it will at least allow you to be able to get or set the value of the flag as you were unsuccessfully trying to do before!
Cheers for now,
Jas.

From the looks of this line:

pDX->m_bSaveAndValidate(FALSE);

It seems to me that you're trying to use a boolean member variable as a function, which is why you're getting that particular error.

I'm pretty certain if you search for the definition of m_bSaveAndValidate it will be declared as a boolean variable NOT as a function which takes a boolean as a parameter.
i.e.

bool m_bSaveAndValidate;

So the reason you are getting that error is because you are trying to use a variable as a function.

If the boolean flag is a public member/property of the class pointed to by pDX, then you should be able to set it directly like this:

pDX->m_bSaveAndValidate = false;

Otherwise, if m_bSaveAndValidate is a private or protected member of whatever class is pointed to by pDX, you will have to use a public function to get or set the value of the flag. If there are currently no public functions in the class which get or set the value of the flag, then you will have to add them to the class yourself.
e.g. in your header:

class YourClass : public WhateverItsDerivedFrom
{
	private: // or it might be under protected!
		bool m_bSaveAndValidate;
		// Other private member variables/functions here

	public:
		// constructor, destructor and other public member variables and functions here
		
		// Accessor functions to get and set the flag
		void SetSaveAndValidate(bool bState){m_bSaveAndValidate = bState;}
		bool GetSaveAndValidate(){return m_bSaveAndValidate;}
};

That way you can call your 'set' function for the flag in your code like this:

pDX->SetSaveAndValidate(false);

Now I'm not sure whether or not that will help with what you want to do, but it will at least allow you to be able to get or set the value of the flag as you were unsuccessfully trying to do before!
Cheers for now,
Jas.

your proposal pretty much depends on whether there's access to definition of the CDataExchange class or not.

your proposal pretty much depends on whether there's access to definition of the CDataExchange class or not.

Ah good point, I haven't done any MFC in a looooong time so I'm rusty as hell!
I wasn't sure what pDX was pointing to, but now that you mention it, pDX... Yes that's probably a pointer to a CDataExchange object...Of course! {facepalm} Doh!

Well, after looking at the definition of CDataExchange, m_bSaveAndValidate is a public member variable, so using:

pDX->m_bSaveAndValidate = FALSE;

Should solve the OP's problem as suggested in my previous post!

Cheers for now,
Jas.

Thank you guys! So that was a beginner mistake. I made the suggested correction, and now I can set the m_bSaveAndValidate member of CDataExchange to FALSE. Thank you!

However, now I found out that setting tha flag to false only allows me to initialize dialog controls with the values of the dialog class data members. I was hoping there was a way to have this happen continuously throughout the life of the dialog. I was able to come up with a solution. I added an event handler to the first edit box EN_Change, so that whenever that dialog's value is changed it updates the data in the 2nd edit box.

I'm going to mark this thread as solved. Thank you guys very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.