• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Accessing CEdit Member Functions Inside CEditView ::MFC

kuphryn

Senior member
Hi.

I think the best approach for the problem I am working on is to use the technique Prosise demostrates in his book using the CStdioFile class. It is a good alternative to serialization.

I need a way to edit the display the data in the file, which are most likely texts. I derived a view from CEditView. I looked to CEditView in MSDN and found that it is possible to get a reference of the CEdit object to modify data currently in the CEditView class. However, Visual C++ displays errors when I tried to gain access to CEdit.

Here is the code:

-----
CEdit myEdit = GetEditCtrl() // I saw this function in MSDN

int i = 0;
CString data;

while (myEdit->GetLine(i, data))
{
myCStringArray.SetAtGrow(i, i + 1);
}
-----

The code above is suppose to copy texts from whatever was stored in the CEdit class into an array of CString.

Visual C++ displayed this error:

C:\Projects\TextView.cpp(121) : error C2440: 'initializing' : cannot convert from 'class CEdit' to 'class CEdit'
No copy constructor available for class 'CEdit'

Am I doing something wrong as far as trying access the CEdit within the CEditView?

Kuphryn
 
Almost right.

From MSDN:
----------------------
CEditView : : GetEditCtrl
CEdit& GetEditCtrl( ) const;

Return Value

A reference to a CEdit object.
-----------------------

Since your code has :
CEdit myEdit = GetEditCtrl()
instead of :
CEdit& myEdit = GetEditCtrl()

you are telling the compiler to create a new CEdit object using the copy constructor instead of what you need, which is to obtain a reference to the existing CEdit object.

p.s. CEdit* myEdit would probably have worked as well, and might have been what you meant to type given the use of - > later
 
Back
Top