Hi,I need to take a valor of a variable CEdit of one .cpp and use it in other .cpp.
I have put this but it doesnt work:
static CString MyVariable;
The compiler works well but in the execution I see that there isnt valor in the new variable.
Help
Hi,I need to take a valor of a variable CEdit of one .cpp and use it in other .cpp.
I have put this but it doesnt work:
static CString MyVariable;
The compiler works well but in the execution I see that there isnt valor in the new variable.
Help
How can I take the valor of a variable of a .cpp to other .cpp?
No-spam Sam
Jeje,I did this this morning and it didnt work.I dont know the reason but when I tried to write in the file,it didnt write anything,only it wrote the information of CEdit of the last dialog,which wrote in the file.
adi151478
{
CEdit m_Edit;
public:
CString GetEditValue() {m_Edit.GetWindowText()};
}
other dialog or CPP file
CString strText = m_pDlg->GetEditValue();
You may have to pass the dialog objects pointer to the other class to access the function.
Another way is to use GetDlgItemText API if you know the resource name.
I'm not sure whether Ihave answered you or not.
Sarah Cameron
You may to provide some access mechanism to access the file. It is not a good practice to make the control variables static.
If you say what you want to achieve, we can say some better way to do the same.
The best way is to provide interface to access or get the value from CEdit or CString.
The extern mechanism will work fine for sharing data. The way you used it sometimes wrong
ReneeC
You can make it as extern.
declare extern CString MyVariable;
in which CPP file where you are using the same variable.
Also dont forget to remove the static from the original definition
I have one suggestion is that, if you are using OOP, this method is not good.
usually, such variables will be declared in the header files. or provide some interfaces to return the handle or value of the same. the meaning of static variables in global scope is to make available to that module (cpp) file only.
NateRickard
stswordman
It has 4 dialogs with one CEdit each one.In the last dialog I have to write in a file all the previous information.In other words in the last dialog(his .cpp or .h,as you want) I have to have access to all variables of CEdits of previous dialogs.Now I have explained better,sorry.Ideas