Class , how to encapsulate this :

This is a discussion on Class , how to encapsulate this : within the C++ Programming forums, part of the General Programming Boards category; ok this my 1st time writing classes so i need help on how to write a class for this : ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    Class , how to encapsulate this :

    ok this my 1st time writing classes so i need help on
    how to write a class for this :
    Code:
    void CADOMFC1View::OnMenuitem32771()
    {
       _RecordsetPtr pRecordSet;
       CADOMFC1Doc * pDoc;
       pDoc = GetDocument();
       _bstr_t bstrQuery("SELECT * FROM App_Student");
       _variant_t vRecsAffected(0L);
       try
       {
         pRecordSet = pDoc->m_pConnection->Execute(bstrQuery,&vRecsAffected,adOptionUnspecified);
         
         if (!pRecordSet->GetadoEOF())
        {
          CListCtrlEx& ctlList = (CListCtrlEx&) GetListCtrl();
          ctlList.DeleteAllItems();
          while(ctlList.DeleteColumn(0));
          ctlList.AddColumn(" ID ",0);
          ctlList.AddColumn(" Name ",1);
          ctlList.AddColumn(" Gender ",2);
          ctlList.AddColumn(" Subject 1 ",3);
          ctlList.AddColumn(" Subject 2 ",4);
          ctlList.AddColumn(" Class ",5);
          int i = 0;
          _variant_t ID;
          _variant_t vName;
          _variant_t cGender;
          _variant_t vSubject1;
          _variant_t vSubject2;
          _variant_t Class;
          while (!pRecordSet->GetadoEOF())
          {
            ID = pRecordSet->GetCollect(L"ID");
            ctlList.AddItem(i,0,(_bstr_t) ID);
            vName = pRecordSet->GetCollect(L"vName");
            ctlList.AddItem(i,1,(_bstr_t) vName);
            cGender = pRecordSet->GetCollect(L"cGender");
            ctlList.AddItem(i,2,(_bstr_t) cGender);
            vSubject1 = pRecordSet->GetCollect(L"vSubject1");
            ctlList.AddItem(i,3,(_bstr_t) vSubject1);
            vSubject2 = pRecordSet->GetCollect(L"vSubject2");
            ctlList.AddItem(i,4,(_bstr_t) vSubject2);
            Class = pRecordSet->GetCollect(L"Class");
            ctlList.AddItem(i,5,(_bstr_t) Class);
    
            pRecordSet->MoveNext();
            i++;
          }
        }
        pRecordSet->Close();
      }
      catch( _com_error &e )
      {
        // Get info from _com_error
        _bstr_t bstrSource(e.Source());
        _bstr_t bstrDescription(e.Description());
        TRACE( "Exception thrown for classes generated by #import" );
        TRACE( "\tCode = %08lx\n", e.Error());
        TRACE( "\tCode meaning = %s\n", e.ErrorMessage());
        TRACE( "\tSource = %s\n", (LPCTSTR) bstrSource);
        TRACE( "\tDescription = %s\n", (LPCTSTR) bstrDescription);
      }
      catch(...)
      {
        TRACE( "*** Unhandled Exception ***" );
      }
    
    }
    THANKS

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    That's the implementation of a member function. What do you mean you want to "write a class" for it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 09:17 AM
  2. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  3. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 03:46 PM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 02:03 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21