locked
how to exchange data between two property pages in the same program

    General discussion

  • i am using Visual C++, i want to exchange data between two property pages in the same program......... means i need the data from a member variable in first property page to the another property page.

    can anybody help me.........

    • Changed type ppdev Tuesday, March 27, 2012 5:06 AM
    Monday, March 26, 2012 11:51 AM

All replies

  • >i am using Visual C++, i want to exchange data between two property pages in the same program......... means i need the data from a member variable in first property page to the another property page.

    Put the data you need to share in the class that is the parent of the
    pages (usually a property sheet), that way both pages can access it by
    using GetParent or having a reference to the data in the parent's
    instance.

    e.g.

    From a property page method, you can access the property sheet like
    this:

    CMyPage1::Method()
    {
        CMySheet * pSheet = (CMySheet *) GetParent();

    Dave

    Monday, March 26, 2012 1:19 PM
  •   i have two property pages with classes MetalTemperatures.cpp,Rupture.cpp.

    In MetalTemperatures class i have one variable like "m_PipeInnerRadius". i need this variable in Rupture.cpp also, how should i access or transfer data from one page to another page means i need the data given to "m_PipeInnerRadius" in MetalTemperatures.cpp to some calculation in Rupture.cpp. "m_PipeInnerRadius" this is local variable in MetalTemperatures.cpp. how should i exchange that variable to Rupture.cpp

    will u please help me.............

    its very urgent........

    ppdev

    Tuesday, March 27, 2012 4:36 AM
  • >will u please help me.............

    My previous reply attempted to give you the general technique. It's
    best if you try to understand that and do it yourself.

    Dave

    Tuesday, March 27, 2012 7:23 AM
  • hi sir,

    i am a beginner to programming, i am unable to get the terminology, i explain to you what i understand,

    but my data is not in propertysheet, that is in propertypage,then how can i share the data between property pages.

    Tuesday, March 27, 2012 8:42 AM
  • >but my data is not in propertysheet, that is in propertypage,then how can i share the data between property pages.

    The key is to put the data you need to share somewhere you can share
    it easily.

    Either
    1. Move the (to be shared) data from the property page to the property
    sheet class and modify code that references the variables so it
    accesses them from the property sheet.

    or:

    2. Add references (or pointers) to each page so that page1's class has
    a reference to page2 and vice versa.

    If you're a beginner, then you're unlikely to find either option easy
    - but learning new tricks is rarely easy.

    Dave

    Tuesday, March 27, 2012 9:49 AM
  • if i declarethe page1 as reference and call the variable of page1 in page2.

    Page1:

    CPage1* page1;

    Page2: 

    CString test;

    test = page1->m_E11; (m_E11 is variable in page1)
     CPropertyPage::OnLButtonDblClk(nFlags, point);

    while compiling the application it gives undeclared identifier as follows

    error C2065: 'page1' : undeclared identifier.

    error C2227: left of '->m_E11' must point to class/struct/union

    Tuesday, March 27, 2012 10:48 AM
  • if i declarethe page1 as reference and call the variable of page1 in page2.

    Page1:

    CPage1* page1;

    Page2: 

    CString test;

    test = page1->m_E11; (m_E11 is variable in page1)
     CPropertyPage::OnLButtonDblClk(nFlags, point);

    while compiling the application it gives undeclared identifier as follows

    error C2065: 'page1' : undeclared identifier.

    Which seems pretty clear to me. The variable "page1" isn't declared at
    the point where you're using it.

    Dave

    Tuesday, March 27, 2012 12:09 PM
  • can u explain me clearly...................

    Tuesday, March 27, 2012 12:13 PM
  • hi sir,

    i declared that CPage1* page1; in my CPage2.cpp and also include the CPage1.h file in the

    CPage2.cpp. now the program is compiled but it does not transfer data from one page to another means i have two edit boxes with variable names as m_E11,m_E12 as CString Type in page1 and another two edit boxes with variable names as m_E21,m_E22 as CString Type in page2.

    now in my CPage2.cpp i did as follows:

    CPage1 *page1;

    m_E21 = page1->m_E11;

    but in the output when i enter a string to the editbox in the page1 (m_E11) it doesnt shows in the second page m_E21;

    i missed something to transfer data........

    can u help me......................

    Tuesday, March 27, 2012 12:53 PM
  • Your approach with page1->m_E11 is not going to work.  Please see your other post on this same question at...

    http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/3bc113b6-0ad1-4a4b-93d6-580a4a24fdcc

    Tuesday, March 27, 2012 1:10 PM
  • ya now only i saw the post, i can try and anydoubt i will ask you................
    Tuesday, March 27, 2012 1:12 PM
  • >but in the output when i enter a string to the editbox in the page1 (m_E11) it doesnt shows in the second page m_E21;

    If you've got 2 edit controls in separate pages then you need to use
    SetWindowText to get the text to update.

    Having said that, it would seem to me that your UI design is odd -
    your shared variable/edit control doesn't really appear as though it
    should be on the page - instead it should be a control on a parent
    window.

    Dave

    Tuesday, March 27, 2012 1:13 PM
  • CMysheet means----------->  is itpropertysheet for the property pages?

    can i declare it in my propertysheet.cpp.

    Tuesday, March 27, 2012 1:15 PM
  • // PropSheet.cpp: implementation of the CPropSheet class.
    //
    //////////////////////////////////////////////////////////////////////
    #include "stdafx.h"
    #include "dataexchange.h"
    #include "PropSheet.h"
    //#include "Page1.h"
    //#include "Page2.h"
    #ifdef _DEBUG
    #undef THIS_FILE
    static char THIS_FILE[]=__FILE__;
    #define new DEBUG_NEW
    #endif
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////
    IMPLEMENT_DYNAMIC(CPropSheet, CPropertySheet)
    CPropSheet::CPropSheet(LPCTSTR szCaption, CWnd *pParent, UINT iSelectPage): CPropertySheet(szCaption, pParent, iSelectPage)
    {
    	
    	AddPage(&P1);
    	AddPage(&P2);
    	CPropSheet* pSheet = (CPropSheet*)GetParent();
    	pSheet->m_E11_1 = m_E11;
    	pSheet->m_E12_1 = m_E12;
    	pSheet->m_E21_1 = m_E21;
    	pSheet->m_E22_1 = m_E22;
    	UpdateData(FALSE);
    }
    CPropSheet::~CPropSheet()
    {
    }
    BEGIN_MESSAGE_MAP(CPropSheet, CPropertySheet)
    END_MESSAGE_MAP()


    // PropSheet.h: interface for the CPropSheet class.
    //
    //////////////////////////////////////////////////////////////////////
    #if !defined(AFX_PROPSHEET_H__81F3D431_D802_4C15_BAD7_FD52576935E0__INCLUDED_)
    #define AFX_PROPSHEET_H__81F3D431_D802_4C15_BAD7_FD52576935E0__INCLUDED_
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    #include "Page1.h"
    #include "Page2.h"
    class CPropSheet : public CPropertySheet  
    {
    	DECLARE_DYNAMIC(CPropSheet)
    public:
    	CPropSheet(LPCTSTR szCaption, CWnd *pParent = NULL, UINT iSelectPage = 0);
    	virtual ~CPropSheet();
    	CPage1 P1;
    	CPage2 P2;
    	CString m_E11_1;
    	CString m_E12_1;
    	CString m_E21_1;
    	CString m_E22_1;
    protected:
    		DECLARE_MESSAGE_MAP()
    private:
    //	CPage1 P1;
    //	CPage2 P2;
    };
    #endif // !defined(AFX_PROPSHEET_H__81F3D431_D802_4C15_BAD7_FD52576935E0__INCLUDED_)

    i insert both code blocks of PropSheet.h and PropSheet.cpp,

    while compiling i got following errors as:

    Compiling...
    PropSheet.cpp
    C:\Temp\dataexchange\PropSheet.cpp(31) : error C2065: 'm_E11' : undeclared identifier
    C:\Temp\dataexchange\PropSheet.cpp(32) : error C2065: 'm_E12' : undeclared identifier
    C:\Temp\dataexchange\PropSheet.cpp(33) : error C2065: 'm_E21' : undeclared identifier
    C:\Temp\dataexchange\PropSheet.cpp(34) : error C2065: 'm_E22' : undeclared identifier
    Error executing cl.exe.

    dataexchange.exe - 4 error(s), 0 warning(s)

    m_E11,m_E12 are variables in page1 and m_E21 and m_E22 are variables in page2.

    Wednesday, March 28, 2012 8:10 AM
  • >> CPropSheet* pSheet = (CPropSheet*)GetParent();
    >> pSheet->m_E11_1 = m_E11;

    It makes no sense to put this in the CPropSheet class. The pages are child windows of the sheet. So the pages can use GetParent to access variables in the sheet.

    Wednesday, March 28, 2012 1:49 PM
  • In this case, variables are not declared in my sheet, the variables are declared in the pages itself. how should i get the variables from the sheet without variables in the sheet.

    ppdev

    Thursday, March 29, 2012 4:12 AM
  • Add some variables to the sheet. Those variables can be accessed from any page.

    Thursday, March 29, 2012 2:04 PM