Link to home
Start Free TrialLog in
Avatar of mjwilliamson
mjwilliamson

asked on

Undeclared Identifier

Hi

I am returning to MFC to find I am a little
rusty on things.

I have a document called XOfficeDoc
and a form called FormDemo.

I call the following from a button event

UpdateData();
NewXOfficeDoc("XOffice.doc",m_str, m_double, m_long);



(NewXOfficeDoc is a member of XOfficeDoc)

m_str, m_double and m_long are bound variables to
edit boxes on my form. I am getting the undeclared
identifier error, I have checked the includes, spelling, headers etc and everything appears fine.

the form knows about the document but wont call
the document function!!!

Any Suggestions
Avatar of cmaryus
cmaryus

> I have a document called XOfficeDoc ?
You mean a class XOfficeDoc ?


>(NewXOfficeDoc is a member of XOfficeDoc)
NewXOfficeDoc is an object of the class XOfficeDoc ?

If so, you must include the header where the class XOfficeDoc is declared in the source file of the form:

#include "XOfficeDoc.h"

...
void CForm::OnSomeButton()
{
...
UpdateData();
NewXOfficeDoc("XOffice.doc",m_str, m_double, m_long);
...
}
Avatar of mjwilliamson

ASKER

exactly - I Have the declaration in the
form code file.

I still get the error!!

Theoretically I know what should be done
- practically I seem to have missed something!
You declared NewXOfficeDoc object?
You declared NewXOfficeDoc object?
You declared NewXOfficeDoc object?
Sorry, maybe I not explain to well.

NewXOffice is a method of XOfficeDoc
so no NewXOfficeDoc object required.

I am basically trying to call the following function

void NewXOfficeDoc(LPCTSTR aTemplate, LPCTSTR aStr, double aDouble, long aLong)
{
     CString str;
     POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition();

     while (pos != NULL) {

          CDocTemplate *temp = AfxGetApp()->GetNextDocTemplate(pos);
          if (temp->GetDocString(str,CDocTemplate::docName) && str == _T("XOffice")) {
               g_template = aTemplate;
               g_str = aStr;
               g_double = aDouble;
               g_long = aLong;
               temp->OpenDocumentFile(NULL);
               return;
          }
     }
}

contained within XOfficeDoc from FormDemo.cpp.

Thanks
just suggestions..

if ur NewXOfficeDoc is member of XOfficeDoc class then:

1: definition should be
void XOfficeDoc::NewXOfficeDoc(LPCTSTR aTemplate, LPCTSTR aStr, double aDouble, long aLong)
{
...
...
}

2: if u calling NewXOfficeDoc from CFrom then XOfficeDoc object   will be required... like

void CForm::OnSomeButton()
{
...
UpdateData();
urXOfficeDoc.NewXOfficeDoc("XOffice.doc",m_str, m_double, m_long);
...
}
GetDocument() could be used if CForm is derived from CView ??????
am i right??????
:-)

to  daknight2000
yep, that's the only ways ...
you're right also about GetDocument()
I think you are right but I found another way of doing
it.

If you put

void NewXOfficeDoc(LPCTSTR aTemplate, LPCTSTR aStr, double aDouble, long aLong);

in the file containing the function call.

I don't know why it works though!


im not sure what to do with the points?
>>I think you are right but I found another way of doing
>>it.

>>If you put

>>void NewXOfficeDoc(LPCTSTR aTemplate, LPCTSTR aStr, >>double aDouble, long aLong);

now NewXOfficeDoc() is a global; thats why u are not getting any errors

:)))

>>void NewXOfficeDoc(LPCTSTR aTemplate, LPCTSTR aStr, >>double aDouble, long aLong);

just a funnction, not a method...
cool

cheers guys
ASKER CERTIFIED SOLUTION
Avatar of daknight2000
daknight2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I did ask what to do with the points but got no answer.

thanks again
Thanks for the points