Solved

CDaoTableDef::CreateField question

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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
Need to retreive data from .TFS file exported by DVR 8 244
mixString challenge 36 134
twoTwo  challenge 35 112
mapAB Challlenge 35 171
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

713 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