Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Edit box behaving strangely

Edit box behaving strangely

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomdebuggingannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fredrik Skog
    wrote on last edited by
    #1

    My edit box code works just fine in debug mode, but it starts behaving very peculiar when I switch to release. Basically, I have a function that looks like this:

    void CTerminalCtrl::GetCurrentLine(CString* strLine)
    {
    int nLines, nLineLength, nRes;
    CString temp;

    nLines = GetLineCount() - 1;
    nLineLength = LineLength();				// Get length of current line
    strLine->Empty();
    GetLine(nLines, strLine->GetBuffer(nLineLength));
    strLine->ReleaseBuffer();
    
    // yadda yadda...
    

    }

    LineLength returns the correct number of characters in the current line, but GetLine always returns zero in release mode, meaning it has copied nothing. strLine will thus be empty. What is going on here? Cheers,
    /Fredrik

    Sonork ID: 100.11430:PhatBoy

    J H 2 Replies Last reply
    0
    • F Fredrik Skog

      My edit box code works just fine in debug mode, but it starts behaving very peculiar when I switch to release. Basically, I have a function that looks like this:

      void CTerminalCtrl::GetCurrentLine(CString* strLine)
      {
      int nLines, nLineLength, nRes;
      CString temp;

      nLines = GetLineCount() - 1;
      nLineLength = LineLength();				// Get length of current line
      strLine->Empty();
      GetLine(nLines, strLine->GetBuffer(nLineLength));
      strLine->ReleaseBuffer();
      
      // yadda yadda...
      

      }

      LineLength returns the correct number of characters in the current line, but GetLine always returns zero in release mode, meaning it has copied nothing. strLine will thus be empty. What is going on here? Cheers,
      /Fredrik

      Sonork ID: 100.11430:PhatBoy

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      The documentation of CEdit::GetLine says that you've got to write the size of the buffer passed on the first word of that buffer. Alternatively, you can use the overload int GetLine(int nIndex,LPTSTR lpszBuffer,int nMaxLength) which does that job for you. I guess this is what it is causing your problem (in debug mode you probably are being lucky and whatever it is written in the buffer when you call GetLine makes the function satisfied). Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      1 Reply Last reply
      0
      • F Fredrik Skog

        My edit box code works just fine in debug mode, but it starts behaving very peculiar when I switch to release. Basically, I have a function that looks like this:

        void CTerminalCtrl::GetCurrentLine(CString* strLine)
        {
        int nLines, nLineLength, nRes;
        CString temp;

        nLines = GetLineCount() - 1;
        nLineLength = LineLength();				// Get length of current line
        strLine->Empty();
        GetLine(nLines, strLine->GetBuffer(nLineLength));
        strLine->ReleaseBuffer();
        
        // yadda yadda...
        

        }

        LineLength returns the correct number of characters in the current line, but GetLine always returns zero in release mode, meaning it has copied nothing. strLine will thus be empty. What is going on here? Cheers,
        /Fredrik

        Sonork ID: 100.11430:PhatBoy

        H Offline
        H Offline
        HintiFlo
        wrote on last edited by
        #3

        Read Joseph M. Newcomers excellent article "Surviving the release" mfg HintiFlo

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups