Solved

CDaoTableDef::CreateField question

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now