Solved

Update a CFormView from CMyDoc

Posted on 1998-07-29
11
362 Views
Last Modified: 2013-11-19
I have a CFromView with three Edit boxes, and when I´ve opened a file using serialize in CMyDoc I would like to update my three variables in CMyView and then update my Window so that it shows my variables. I´m a newbie and are there anybody who knows a good and easy way to do this, I´d appriciate the code written out. Thanx...
0
Comment
Question by:joakimf
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 1

Expert Comment

by:Andy_Keys
ID: 1319915
The easiest way is to use classwizrd to define variable for each of the edit boxes using the members variable tab

Lets say the variable are called m_Var1,m_Var2,m_Var3
they should be public tby default
so you can use somthing like
 MyView->m_var = xxxx etc etc
The use UpdateData( FALSE ) to transfer data from the variable to the control. UpdateData( TRUE ) will do the oposite when you want to update the variable ready for storing
Hope this at least gets you started
0
 
LVL 1

Author Comment

by:joakimf
ID: 1319916
I´m sorry I didn´t state my question clear enough I try to be more specific.
I´ve got the variables through ClassWizard but I can´t use them in CMyDoc because I don´t know how to create a pointer to the CMyView class. I´ve tried to set
CMyView* pView=GetFirstView();
pView->m_MyVariable;
It doesn´t work, so I would like some help how to do something like that.
0
 
LVL 1

Expert Comment

by:Andy_Keys
ID: 1319917
How have you created CMyView. If its done through a doc template then it should be added to the doc by the framework.  if not when you create the view call pDoc->AddView( pMyView );
Then when you call getFirstview/ Get next view you will have to use the pView->IsKindOf(RUNTIME_CLASS(CMyView) ) to ensure that the ptr is pointing to you class. Then you should be able to set the variable
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:joakimf
ID: 1319918
CMyView was created when I made the project in MFC App Wizard, and one of the problem is that I can´t include CMyView.h in the CMyDoc.cpp file som I don´t reach the CMyView class in CMyDoc when i try to compile I get error saying that the variables are unidentified.
Maybe it wasn´t such an easy question so I´ve increased the points.
0
 
LVL 1

Expert Comment

by:Andy_Keys
ID: 1319919
I don't see why you can't include the header file. Post the code
for the Doc and View ( headers as well) as it help ( or just email them to me if you dont want to make them public) keyan01@cai.com
0
 
LVL 1

Author Comment

by:joakimf
ID: 1319920
Okey, will do as soon as possible..
0
 
LVL 3

Expert Comment

by:danny_pav
ID: 1319921
I never have the document access the view directly.  I use CDocument::UpdateAllViews(); and have the view use its GetDocument() and get the data accordingly.
0
 
LVL 8

Accepted Solution

by:
trestan earned 70 total points
ID: 1319922
I think I can give you an answer, since I've done it before.
In your CMyDoc.cpp under Serialize function call UpdateAllViews (NULL); after you input the data from the data file. Then in your View, add a function OnUpdate(), in this function add these codes: CMyDoc* pDoc = GetDocument(); input the value to the data member in the View, then call UpdataData();
That's it. Good luck.


0
 
LVL 1

Author Comment

by:joakimf
ID: 1319923
Thanx for your comment danny_pav, but my real problem is hoe to transfer data from a global variable to my variables in CMyView wich are connected to my edit boxes...
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319924
While I am writing the answer, danny_pav provided a similiar comment. I think you declared some variable corresponding to those in CView. Use the pointer *pDoc in View, you can access the variables you declared in CDoc. Try it. There should be no problem.
0
 
LVL 1

Author Comment

by:joakimf
ID: 1319925
Thanx trestan, it worked perfectly. Enjoy the points....
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
move a line in eclipse 3 107
modThree challenge 4 98
FizzBuzz challenge 9 82
Annoying "thing" blocks my view 4 117
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question