Solved

CDaoTableDef::CreateField question

Posted on 2002-05-01
5
385 Views
Last Modified: 2013-11-20
    CDaoFieldInfo fiResultsNewValue01;
     fiResultsNewValue01.m_strName="NewValue01";
     fiResultsNewValue01.m_nType=dbInteger;
     fiResultsNewValue01.m_lSize=dbInteger;
     fiResultsNewValue01.m_lAttributes=dbUpdatableField;
     fiResultsNewValue01.m_bRequired=true;


     CString strResultsMDB = "Results.mdb";
     static CDaoDatabase  dbResults;
     dbResults.Open(strResultsMDB,FALSE,FALSE);
     m_pdbResults = &dbResults; //assign pointer to static db

     CDaoTableDef* tdNew = new CDaoTableDef(m_pdbResults);
     tdNew->Create(csNewFeatureTable);

/* error C2664: 'void __thiscall CDaoTableDef::CreateField(struct CDaoFieldInfo &)' : cannot convert parameter 1 from 'struct CDaoFieldInfo *' to 'struct CDaoFieldInfo &' */
     tdNew->CreateField(&fiResultsNewValue01);

     tdNew->Append();
     tdNew->Close();
     delete tdNew;
According to MSDN this is funtion prototype:
void CreateField( CDaoFieldInfo& fieldinfo );

Question: Where did I go wrong?

Thanx
Dave
0
Comment
Question by:Smave
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:gandalf79
ID: 6984948
The problem is you you are tring to pass a pointer to the fuction. You simply need to remove the & so that it reads.

tdNew->CreateField(fiResultsNewValue01);

The & in "tdNew->CreateField(&fiResultsNewValue01);" meens you are sending the fuction the address of the varible. The & in the funtion prototype "void CreateField( CDaoFieldInfo& fieldinfo );" meens instead of making a copy of the varible(the normal behavier) use the original.

This differance can be very confusing since the same operator meens several things given different situations.


0
 
LVL 2

Accepted Solution

by:
gandalf79 earned 100 total points
ID: 6985057
The problem is you you are tring to pass a pointer to the fuction. You simply need to remove the & so that it reads.

tdNew->CreateField(fiResultsNewValue01);

The & in "tdNew->CreateField(&fiResultsNewValue01);" meens you are sending the fuction the address of the varible. The & in the funtion prototype "void CreateField( CDaoFieldInfo& fieldinfo );" meens instead of making a copy of the varible(the normal behavier) use the original.

This differance can be very confusing since the same operator meens several things given different situations.


0
 
LVL 3

Expert Comment

by:job_s
ID: 6985504
  static CDaoDatabase  dbResults;
    dbResults.Open(strResultsMDB,FALSE,FALSE);
    m_pdbResults = &dbResults; //assign pointer to static db

I don't know why ur using this method;

try this .I think this is better than Ur code

//once allocate new CDaoDatabase  
m_pdbResults = new CDaoDatabase  ;

m_pdbResults->Open( strResultsMDB,FALSE,FALSE);
0
 
LVL 3

Expert Comment

by:job_s
ID: 6985507
U can avoid the Error by giving

 CDaoTableDef* tdNew = new CDaoTableDef(*m_pdbResults);

on current code
0
 
LVL 3

Expert Comment

by:job_s
ID: 6985513
Sorry my last comment is not valid happened by mistake

   gandalf79 is right



0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 54
Shell script to login to remote m/c and execute commands 10 80
NotAlone Challenge 20 92
building a service to accessed via telnet client, want colors ? 4 106
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question