<< Return to Main Index

< Return to Class Index

class CGXRecSetInfo : public CObject

CGXRecSetInfo is used by CGXBrowseParam to store information about the data source, the query string and the filename.

CGXBrowseParam owns a pointer to a CGXRecSetInfo info object. Once you call CGXBrowseParam::CreateRecSetInfo, an CGXRecSetInfo object will  be instantidated and attached to CGXBrowseParam. CGXBrowseParam takes care the object gets properly destroyed when CGXBrowseParam is deleted.

CGXBrowseParam also serializes the CGXRecSetInfo object.

This enables you to very easily store query information into the CGXBrowseParam object and later retrieve this information when CGXBrowseParam gets restored from a document.

If necessay you can subclass CGXRecSetInfo and add additional attributes.

See the example how to add support for scheme information to your browser view.

#include <gxall.h>

Example

This example shows how to add support for serializing query information to your dao query view:

void CDaoqueryView::OnInitialUpdate()
{
   CDaoqueryDoc* pDoc = GetDocument();

   BOOL bFirstView = FALSE;

   if (pDoc->m_pParam == NULL)
   {
      bFirstView = TRUE;
         // bFirstView = TRUE indicates that this is
         // the first view connected to the document
         // and therefore the data need to be intialized.

      // construct parameter object
      pDoc->m_pParam = new CGXDaoParam;
   }
   // else
      // No data need to be initialized. They are already available in the document.

   // pass the pointer to the grid view
   SetParam(pDoc->m_pParam, FALSE);
                       // ^-- indicates that document is responsible
                       // for deleting the object.


   // Attach the recordset object
   SetDatabase(&pDoc->m_database, FALSE);
   SetRecordset(&pDoc->m_dynamicSet);

   if (!InitFromRecSetInfo())
      SetRecordset(NULL);

   // standard initialization, will create other objects
   // such as column names, widths, base styles, ...
   CMyDaoRecordView::OnInitialUpdate();

   // Enable Objective Grid internal update-hint mechanism
   EnableHints();
}

BOOL CDaoqueryView::InitFromRecSetInfo()
{
   CDaoDatabase* pDatabase = GetDatabase();
   ASSERT(pDatabase);

   CDaoRecordset* pSet = OnGetRecordset();
   ASSERT(pSet);

   CGXBrowseParam* pParam = GetBrowseParam();

   CString strQuery;

   if (pSet->IsOpen())
      return TRUE;

   CGXRecSetInfo* pInfo = pParam->GetRecSetInfo();

   if (pInfo == NULL)
   {
      pParam->CreateRecSetInfo();
      pInfo = pParam->GetRecSetInfo();

      CString strFileName;
      // Open the Access database
      if (!pDatabase->IsOpen())
      {
         // pop-up file-open dlg to ask for location
         CFileDialog dlgFile(
            TRUE,
            _T(".mdb"),
            NULL,
            OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
            _T("Access Files (*.mdb)|*.mdb|All Files (*.*)|*.*||"));

         if (dlgFile.DoModal() == IDCANCEL)
            return FALSE;
         try
         {
            pDatabase->Open(dlgFile.GetFileName());
         }
         catch (CDaoException* e)
         {
            // Tell them the reason it failed to open
            AfxMessageBox(e->m_pErrorInfo->m_strDescription);
            e->Delete();
            return FALSE;
         }

         strFileName = dlgFile.GetFileName();
      }

      if (!pDatabase->IsOpen())
         return FALSE;

      // pop-up query dialog, so that the user can specify the
      // SQL Query for recordset

      CMyQueryDialog dlg;
      if (dlg.DoModal() == FALSE)
         return FALSE;

      strQuery = dlg.m_sSQLString;
      //Intitialize the recordset info
      pInfo->m_strSqlQuery = strQuery;
      pInfo->m_strFileName = strFileName;
   }
   else
   {
      // we already have recordset info

      // Open the Access database
      if (!pDatabase->IsOpen())
      {
         CString strFileName = pInfo->m_strSource;
         if (strFileName.IsEmpty())
         {
            // pop-up file-open dlg to ask for location
            CFileDialog dlgFile(
               TRUE,
               _T(".mdb"),
               NULL,
               OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
               _T("Access Files (*.mdb)|*.mdb|All Files (*.*)|*.*||"));
            if (dlgFile.DoModal() == IDCANCEL)
               return FALSE;

            strFileName = dlgFile.GetPathName();
         }

         try
         {
            pDatabase->Open(strFileName);
         }
         catch (CDaoException* e)
         {
            // Tell them the reason it failed to open
            AfxMessageBox(e->m_pErrorInfo->m_strDescription);
            e->Delete();
            return FALSE;
         }
      }

      if (!pDatabase->IsOpen())
         return FALSE;

      // pop-up query dialog, so that the user can specify the
      // SQL Query for recordset
      strQuery = pInfo->m_strSqlQuery;
      if (strQuery.IsEmpty())
      {
         CMyQueryDialog dlg;
         if (dlg.DoModal() == FALSE)
            return FALSE;
         strQuery = dlg.m_sSQLString;
      }
   }

   // Now, open the recordset

   // turn off MFC double-buffering mechanism because
   // CDAORecordView will manually call SetFieldDirty / SetFieldNull
   pSet->m_bCheckCacheForDirtyFields = FALSE;

   try
   {
      pSet->m_pDatabase = pDatabase;
      pSet->Open(AFX_DAO_USE_DEFAULT_TYPE, strQuery);
   }
   catch (CDaoException* e)
   {
      // Tell them the reason it failed to open
      AfxMessageBox(e->m_pErrorInfo->m_strDescription);
      e->Delete();
      return FALSE;
   }

   if (!pSet->IsOpen())
      return FALSE;

   return TRUE;
}

See Also

CGXBrowseParam CGXBrowseParam::CreateRecSetInfo