Inherited Property Example (VC++)

This example creates a Recordset object from a QueryDef object, creates a new property, and indicates whether the property is inherited. Then the example prints the name of each field in the Recordset and, for each property of each field, it prints the Name, Type, Value, and Inherited property value settings.

CdbDBEngine      dbeng;
CdbDatabase      dbsDefault; 
CdbQueryDef      qdfTest;
CdbRecordset   rstTest; 
CdbProperty      prp;
CdbField      fld;
COleVariant      vVal;
int             intField, intFieldMax, 
            intProp, intPropMax;
//
dbsDefault = dbeng.OpenDatabase(_T("Northwind.mdb"));
qdfTest = dbsDefault.QueryDefs[0L];
prp = 
   qdfTest.CreateProperty(
      _T("Moose"),dbBoolean, TRUE);
qdfTest.Properties.Append(prp);
rstTest = qdfTest.OpenRecordset();

printf(_T("Is rstTest.Properties(\"Moose\")inherited? %i\n"), 
   qdfTest.Properties[_T("Moose")].GetInherited());
printf(_T("Is rstTest.Properties(\"Moose\")inherited? %i\n"),          rstTest.Properties[_T("Moose")].GetInherited());

intFieldsMax = rstTest.Fields.GetCount();
for (intField = 0; intField < intFieldsMax; intField++)
{
   fld = rstTest.Fields[intField];
   printf(_T(fld.GetName()));

   //On Error Resume Next
   intPropMax = fld.Properties.GetCount(); 
   for (   intProp = 0; 
         intProp < intPropMax;
         intProp++)
   {
   try {   // Ignore write-only properties.
      prp = fld.Properties[intProp];
      printf(_T(prp.GetName()));
      printf(" %i", prp.GetType());
      vVal = prp.GetValue();
      vVal.ChangeType(VT_BSTR);
      printf(" %S", vVal.bstrVal);
      printf(" %i\n", prp.GetInherited());
      }
   catch (CdbException) 
      {}
   }
   
}