Thread: Accesing data from App in Doc

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    27

    Accesing data from App in Doc

    Hi all,
    A bit of advice using MFC needed really. I want to be able to set a variable m_PopSize (which is declared in "App.h") to generate an array (LineArray) of objects in "Doc.cpp" whoose size depends on the value stored in m_PopSize. e.g. is PopSize is 100 then:
    LineArray[100].
    I seem to have to do it this way because if i put
    LineArray[m_PopSize] it says it expects a constant even if i declare m_PopSize as a const int.

    Any way, on OnNewDocument() I want to create this array. So I have put in the following bit of code.
    Code:
    BOOL CWinLinesDoc::OnNewDocument()
    {
    	if (!CDocument::OnNewDocument())
    		return FALSE;
    
    	// TODO: add reinitialization code here
    	poly4toline4(); //set up the map for vector usage
    	srand( (unsigned)time( NULL ) ); //get time for random numbers
    	HasGenerateDone = 0;//generate button has not been pressed yet
    	BestSearch = 0;
    	if(CWinLinesApp.m_PopSize == 100)
    		CLine LineArray[100];
    
    
    	// (SDI documents will reuse this document)
    
    	return TRUE;
    }
    Note this was just a test, normally I would include if(m_PopSize == ) for all the other possibilities. However when I try and run this it says:
    Code:
    \WinLinesDoc.cpp(54) : error C2143: syntax error : missing ')' before '.'
    if I omitt the CWinLinesApp bit it says that m_PopSize is not defined. Is there any way to get around this, or even better a way I can initialise an object array without needing a const variable.
    Many thanks for your time.
    Dylan

  2. #2
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    170
    You could try AfxGetApp()
    Code:
    if(  ((CWinLinesApp*)AfxGetApp())->m_PopSize == 100  )
    Last edited by Scarlet7; 04-16-2003 at 03:03 PM.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    27

    Cheers

    Thanks, i'll give it a go.
    Much appreciated

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  2. Accesing pointer to struct data
    By mosu' in forum C++ Programming
    Replies: 7
    Last Post: 07-18-2006, 10:01 AM
  3. Reading a file with Courier New characters
    By Noam in forum C Programming
    Replies: 3
    Last Post: 07-07-2006, 09:29 AM
  4. C diamonds and perls :°)
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 05-16-2003, 10:19 PM
  5. C Programming Question
    By TK in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 07-04-2002, 07:11 PM