Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have made a file open dialog, it contains an edit control whose variable is "path" that contains the file name. what i want is to use this variable's value in other dialogs but it gives the error that "path" is an undeclard identifier.

C#
class CAboutDlg : public CDialog
{
public:
    CAboutDlg();
    static CString imgname;



in the same class, i used it like this
C++
CString image=CAboutDlg::imgname;
 CString szFilename(image);


and passing value of path by this code
MIDL
path=dlg.GetPathName();
UpdateData(FALSE);
CAboutDlg::imgname=path;


but it still gives error that CAboutDlg and imgname are undeclared identifier in the above code in which i m passing value of path. i did the same which i learned from the site now what's wrong with that?:confused:
Posted
Updated 1-Jul-10 23:02pm
v2

You have several options for doing that.
The easiest but the ugliest would be to declare your path as a global variable.
A much better approach would be to have something like a class wrapping some options of your program. This class would then be instanciated as a singleton which would be accessible by every part of your program (google for "singleton pattern" for more information).
 
Share this answer
 
Comments
Sweety Khan 2-Jul-10 3:47am    
i wanna do the easiest and the ugliest way. but how can i declare path as a global variable? as when i right click on an edit control->add variable, access has only three options private,protected, public.
Cedric Moonen 2-Jul-10 3:53am    
You certainly won't put your edit control as a global variable. Instead, when the user pressed the Ok button, you get the text from the edit control and store it in the global variable (which is a string).
Sweety Khan 2-Jul-10 4:49am    
i learned the declaration of global variables from this site http://www.codeguru.com/cpp/cpp/cpp_mfc/article.php/c803. what i have done, i m showing it in my question. plz see
Sweety Khan 2-Jul-10 15:42pm    
thanxxxx everyone its done
Sounds like your problem is that you cannot access the CAboutDlg class at all from that specific part of the program. In MDI/SDI applications the code wizard puts declaration (and implementation) of the CAboutDlg in the App .cpp file. You might need to move the class declaration to your header file (or a new header file) and make sure you include that in the file you want to access it from.

Seems a bit ugly though. Make a settings class and pass along an instance of it instead like Cedric suggested.
 
Share this answer
 
Simple enough question. The answer really depends on how the app is set up if this is a dialog based app this is as easy as calling the CEditControl::GetWindowText() ,your EditControl would obviously need a control variable to be able to use the GetWindowText() method, whenever you need the text.

You could always create a global variable and store the string when ever this is changed by creating an event handler.


Is this an MDI or SDI app? In the case that this is dialog is not the main dialog/frame I am assuming it is created and instantiated by a calling function and only exists within the scope of that function. So you need to get the information while the getting is good so to speak.

In the vein of:

YourFunc()
{
yourDlgClass FileDLG;

if(FileDLG.doModal() == ID_OK)
{
YourGlobalString = FileDLG.imgname;
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900