Solved

CDaoTableDef::CreateField question

Posted on 2002-05-01
5
386 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

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!

Question has a verified solution.

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

Introduction: Finishing the grid ā€“ keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. ā€¦
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this vā€¦

705 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