capable of creating dynamic binding by hand???
Dave Bartmess -- dbartmess@jkinc.com Monday, March 10, 1997 Environment: Win 95 / VC++ 4.2b I am trying to create a dynamic binding of various tables in a server application with no GUI frontend at all. The columns are to be bound to an array of Field objects that I have created that hold the value, data type, column name, etc, of the columns in many tables, all of which are different, but handled through one generic interface. The problem is, I can't use the Class Wizard for this (as far as I've been able to see) because the Class Wizard wants to add a specific table and static column binding. NONE of the columns can be statically bound, since the database may change on the fly due to legislative changes that HAVE to be implemented in short order. The problems are: 1> I haven't found any reference to where the CFieldExchange * is created, or how. This has to be present, but from the gist of the HELP screens in VC++, it looks like the code is being generated on the fly by the compiler. 2> What calls the DoFieldExchange() function? It looks like (from the HELP screens again) that the DoFieldExchange() function is called by the CRecordset Open() call. If so, how do I pass in the CFieldExchange * that it looks like I will have to create myself? I'd appreciate any help with this. I'm already past my deadline before this problem hit, mostly due to the fact that the DAO database classes are not thread-safe...
David -- YoskowitzD@andovercontrols.com Friday, March 14, 1997 [Mini-digest: 2 responses] Since you've already created an array of field objects, it sounds like all you need to do is write a DoFieldExchange in your CRecordset-derived class that loops through the fields objects, checks the data type of each one, and then calls the appropriate RFX function passing it the column name and data value. As you stated, you cannot use the Class Wizard to do this. Your DoFieldExchange will be called by the base class (CRecordset) methods such as Open, SetFieldNull, etc. It should look like this: void CMyRecordset::DoFieldExchange(CFieldExchange* pFX) { // loop through output columns pFX->SetFieldType(CFieldExchange::outputColumn); for (int i = 0; i < fields.GetCount(); i++) { // select the appropriate RFX based on the data type // (e.g. for TINYINT, use RFX_Byte) switch (fields[i].DataType) { case TINYINT: RFX_Byte(pFX, fields[i].ColumnName, fields[i].DataValue); break; } } } >---------- >From: Dave Bartmess[SMTP:dbartmess@jkinc.com] >Sent: Monday, March 10, 1997 5:00 PM >To: mfc-l@netcom.com >Subject: capable of creating dynamic binding by hand??? > >Environment: Win 95 / VC++ 4.2b > >I am trying to create a dynamic binding of various tables in a server >application with no GUI frontend at all. The columns are to be bound to an >array of Field objects that I have created that hold the value, data type, >column name, etc, of the columns in many tables, all of which are >different, but handled through one generic interface. > >The problem is, I can't use the Class Wizard for this (as far as I've been >able to see) because the Class Wizard wants to add a specific table and >static column binding. NONE of the columns can be statically bound, since >the database may change on the fly due to legislative changes that HAVE to >be implemented in short order. > >The problems are: > >1> I haven't found any reference to where the CFieldExchange * is created, >or how. This has to be present, but from the gist of the HELP screens in >VC++, it looks like the code is being generated on the fly by the compiler. > >2> What calls the DoFieldExchange() function? It looks like (from the HELP >screens again) that the DoFieldExchange() function is called by the >CRecordset Open() call. If so, how do I pass in the CFieldExchange * that >it looks like I will have to create myself? > >I'd appreciate any help with this. I'm already past my deadline before this >problem hit, mostly due to the fact that the DAO database classes are not >thread-safe... > -----From: Joao VargemDave Bartmess wrote: > > Environment: Win 95 / VC++ 4.2b > > I am trying to create a dynamic binding of various tables in a server > application with no GUI frontend at all. (...) > The problems are: > > 1> I haven't found any reference to where the CFieldExchange * is created, > or how. This has to be present, but from the gist of the HELP screens in > VC++, it looks like the code is being generated on the fly by the compiler. > > 2> What calls the DoFieldExchange() function? It looks like (from the HELP > screens again) that the DoFieldExchange() function is called by the > CRecordset Open() call. If so, how do I pass in the CFieldExchange * that > it looks like I will have to create myself? > Hi. You don't need to know where the CFieldExchange is created and it is called by the UpdateData() function. All you have to do is put you binding code inside the DoFieldExchange function, and the function gets called when it's necessary. There is an example in the MSVC infoviewer that may help you. The sample is in: MFC Samples\Database Samples\ Dynabind. -- Joao Vargem (jpv.loyaltech@taguspark.pt) LoyalTech Portugal SA Oeiras, Portugal
Become an MFC-L member | Вернуться в корень Архива |