Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

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
0
mjwilliamson
Asked:
mjwilliamson
  • 6
  • 6
  • 4
1 Solution
 
cmaryusCommented:
> 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);
...
}
0
 
mjwilliamsonAuthor Commented:
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!
0
 
cmaryusCommented:
You declared NewXOfficeDoc object?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
cmaryusCommented:
You declared NewXOfficeDoc object?
0
 
cmaryusCommented:
You declared NewXOfficeDoc object?
0
 
mjwilliamsonAuthor Commented:
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
0
 
daknight2000Commented:
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??????
:-)

0
 
cmaryusCommented:
to  daknight2000
yep, that's the only ways ...
you're right also about GetDocument()
0
 
mjwilliamsonAuthor Commented:
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!


0
 
mjwilliamsonAuthor Commented:
im not sure what to do with the points?
0
 
daknight2000Commented:
>>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

:)))

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

just a funnction, not a method...
0
 
mjwilliamsonAuthor Commented:
cool

cheers guys
0
 
daknight2000Commented:
how about giving some points?
0
 
mjwilliamsonAuthor Commented:
I did ask what to do with the points but got no answer.

thanks again
0
 
daknight2000Commented:
Thanks for the points
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 6
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now