Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CDaoTableDef::CreateField question

Posted on 2002-05-01
5
Medium Priority
?
390 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 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses

618 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