Home > Software engineering >  Help: MFC single document view variable transmission error
Help: MFC single document view variable transmission error

Time:11-09

I made up a single document View program, need to transfer production from a View to another View, in accordance with the CSDN recommended method, we use the * * * Doc assignment intermediate variable transmission, try the wrong:

(this is the recommended method) in CSDN in single document View of programming, a lot of data transfer between multiple views, here to write one of the most simple, only write in any View: XXXDoc * pDoc=(XXXDoc *) GetDocument (); To get Doc class pointer, since in any one of the View class can access to the Doc in the class member variable, you can use Doc class as the data transfer of a middle class! For example, have A class A, B, C, the B class for the Doc, A and C for the View class, assume that A data in the data in A to C C, to create A public variable in the B, B, and then in, must carry on the data transmission in the class A place to write: BDoc * pDoc=(BDoc *) GetDocument (); PDoc - & gt; B=a; To write in class C: BDoc * pDoc=(BDoc *) GetDocument (); C=pDoc - & gt; b; This time, a it has successfully to c!

Inspection for a moment, I am FirstView ontouch () function call * * * in the Doc variable, use the pDoc - & gt; Enable prompt Doc * * * defined in the middle of the variables, and software compilation that's right, but the operation error, error as shown,
I know it's c=pDoc - & gt; B, because I to pDoc - & gt; B=c assignment statement, wrong to turn into a "memory not to write",

A great god, please help, thank you very much!

CodePudding user response:

 
CWinApp * pApp=AfxGetApp ();
The POSITION PosDocTemplate=pApp - & gt; GetFirstDocTemplatePosition ();
While (PosDocTemplate)
{
CDocTemplate * pDocTemplate=pApp - & gt; GetNextDocTemplate (PosDocTemplate);

The POSITION PosDoc=pDocTemplate - & gt; GetFirstDocPosition ();
While (PosDoc)
{
CDocument * pDoc=pDocTemplate - & gt; GetNextDoc (PosDoc);

The POSITION PosView=pDoc - & gt; GetFirstViewPosition ();
While (PosView)
{
The CView * pView=pDoc - & gt; GetNextView (PosView);

}
}
}



CodePudding user response:

Not a single document?

CodePudding user response:

Such as:
Void CFileView: : OnActivateView (BOOL bActivate, CView * pActivateView, CView * pDeactiveView)
{
The CView: : OnActivateView (bActivate pActivateView, pDeactiveView);
If (GetDocument () - & gt; IsKindOf (RUNTIME_CLASS (CPViewDoc)))
TheApp. SetStatusBarText (((CPViewDoc *) GetDocument ()) - & gt; SzStatusMessage);
The else
TheApp. SetStatusBarText (((CViewfileDoc *) GetDocument ()) - & gt; SzStatusMessage);
}

CodePudding user response:

refer to the second floor schlafenhamster response:
is not a single document?

Single document view, multiple view

CodePudding user response:

reference 1st floor zgl7903 response:
 
CWinApp * pApp=AfxGetApp ();
The POSITION PosDocTemplate=pApp - & gt; GetFirstDocTemplatePosition ();
While (PosDocTemplate)
{
CDocTemplate * pDocTemplate=pApp - & gt; GetNextDocTemplate (PosDocTemplate);

The POSITION PosDoc=pDocTemplate - & gt; GetFirstDocPosition ();
While (PosDoc)
{
CDocument * pDoc=pDocTemplate - & gt; GetNextDoc (PosDoc);

The POSITION PosView=pDoc - & gt; GetFirstViewPosition ();
While (PosView)
{
The CView * pView=pDoc - & gt; GetNextView (PosView);

}
}
}


The second method is recommended, is to iterate through all the view, can you explain it in detail? Used in this passage? In the Doc GetFirstViewPosition ()? I didn't see assignment statements, that how to pass variables? Don't understand, oh...

CodePudding user response:

To respond to comments the zeal of a friend,
Tried CSDN today day recommended by two methods, one is using the Doc transfer, another kind is to iterate through all the view class), did not succeed,
Suddenly want to try direct call pointer: direct use in bview aview, actually implemented, is in bview ontouch (), use aview * paview=(aview *) pMain - & gt; GetActiveView (); Then use b=paview - & gt; Actually put a value passed to the b!
Really don't understand, if direct calls can be done, why you even bother trying to turn around? Please the great god express

CodePudding user response:

Saying the built-in CDocument: : UpdateAllViews without yao... The need to inform the data broadcast in the past, each view themselves in the OnUpdate write processing code

CodePudding user response:

More convenient you directly define a global variable, c + + classes is to encapsulate the data, b=paview - & gt; A. the a it exposes
  • Related