eVC++: Probleme mit CEdit::GetLine



  • Hallo,
    ich versuche gerade den Inhalt eines Editfeldes in eine String Variable zu speichern. Mein Editfeld ist nun schon vom Typ CEdit, aber mit der Funktiojn GetLine habe ich so meine Probleme. Die Hilfe schreibt folgendes:

    int GetLine(
    int nIndex,
    LPTSTR lpszBuffer )
    const;

    int GetLine(
    int nIndex,
    LPTSTR lpszBuffer,
    int nMaxLength )
    const;

    Parameters
    nIndex
    Specifies the line number to retrieve from a multiple-line edit control. Line numbers are zero-based; a value of zero specifies the first line. This parameter is ignored by a single-line edit control.
    lpszBuffer
    Points to the buffer that receives a copy of the line. The first word of the buffer must specify the maximum number of bytes that can be copied to the buffer.
    nMaxLength
    Specifies the maximum number of bytes that can be copied to the buffer. GetLine places this value in the first word of lpszBuffer before making the call to Windows CE.

    Da ich nur eine Zeile auslesen will, haben ich es mal so versucht:

    m_Edit2.GetLine(0,buf,256);

    Geht natürlich nicht, vor allem wegen des buffers, ich weis nicht genau wie ich damit umgehen soll. Als Beispiel steht in der Hilfe:

    int i, nLineCount = pmyEdit->GetLineCount();
    CString strText, strLine;

    // Dump every line of text in the edit control.
    for (i=0;i < nLineCount;i++)
    {
    pmyEdit->GetLine(i, strText.GetBuffer(pmyEdit->LineLength(i)));
    strText.ReleaseBuffer();

    strLine.Format(TEXT("line %d: '%s'\r\n"), i, strText.GetBuffer(0));
    afxDump << strLine;
    }

    Leider verstehe ich auch den Code kaum. Kann mir jemand von euch auf die Sprünge helfen?
    MfG
    Basti


  • Mod

    Die zweite Methode ist weitaus einfacher. Wenn Du die erste Variante verwendest musst Du die Größe selber setzen.
    Also Dir einen Buffer holen und dann einfach CString::GetBuffer/Release verwenden, oder CStrBuf.

    Also:

    CString str;
    pmyEdit->GetLine(i,str.GetBuffer(256),256);
    str.ReleaseBuffer();
    

    Oder eben:

    CString str;
    pmyEdit->GetLine(i,CStrBuf(str,256),256);
    

Anmelden zum Antworten