FF_TextBox_GetLine error

Started by Pat Dooley, June 15, 2010, 09:56:00 AM

Previous topic - Next topic

Pat Dooley

I have discovered that Paul has made an error in a FF function. I know, I know. When I discovered the problem, my vision blurred and I became quite nauseous. How could this be? The boss said I should stay home for a couple days with pay (Good Going, Paul!).

OK, here is the problem. The FF_TEXTBOX_GETLINE function doesn't work. Test it with a multiline textbox having lines of different lengths.

The problem is in calculating the buffer size.
'wrong
nBufferSize = SendMessage(hWndControl, %EM_LINELENGTH, nLineNumber, 0)


Here's the fix

Add
Local nCharIndex As Long

Change this
' Get the length of the text
  nBufferSize = SendMessage(hWndControl, %EM_LINELENGTH, nLineNumber, 0)


to this
' Get the length of the text
  nCharIndex=SendMessage (hWndControl, %EM_LINEINDEX, nLineNumber,0)
  nBufferSize = SendMessage(hWndControl, %EM_LINELENGTH, nCharIndex, 0)


Now I can see again.

Paul Squires

Thanks Pat  :D

I tried both versions of the code and I really didn't notice anything different. I trust that you have tested it much more so than I have, so I'll use your code just to be safe.

(BTW, line numbers for this function are zero based so if you want, say, Line 5 then you need to pass 6 for the line number to retrieve).

Thanks!
Paul Squires
PlanetSquires Software

Pat Dooley

Using the original function, try entering a short line followed by a much longer line.
here is my calling code:
'--------------------------------------------------------------------------------
Function FORM1_COMMAND1_BN_CLICKED ( _
                                   ControlIndex     As Long,  _  ' index in Control Array
                                   hWndForm         As Dword, _  ' handle of Form
                                   hWndControl      As Dword, _  ' handle of Control
                                   idButtonControl  As Long   _  ' identifier of button
                                   ) As Long
Local nLineCount As Long
Local nLineNumber As Long
Local tmp As String

nLineCount=FF_TextBox_GetLineCount( HWND_FORM1_TEXT1 )
For nLineNumber=0 To nLineCount-1
   tmp=FF_TextBox_GetLine( HWND_FORM1_TEXT1, nlinenumber )
   MsgBox tmp
Next x

End Function


Pat Dooley

I have noticed that enabling theme support really messes with this function.

José Roca

The main problem is that your are not indicating the size of the buffer, that must be set in the first word of the buffer.

I use the following:


FUNCTION Edit_GetLine (BYVAL hEdit AS DWORD, BYVAL which AS DWORD) AS STRING
   LOCAL buffer AS STRING
   LOCAL n AS LONG
   buffer = MKI$(32765) + STRING$(32765, 0)
   n = SendMessage(hEdit, %EM_GETLINE, which, STRPTR(buffer))
   FUNCTION = LEFT$(buffer, n)
END FUNCTION


Pat Dooley

Somehow I was thinking the buffer size was for the particular line of the textbox you wanted to get. It appears you are setting the buffer to handle the entire textbox.
Thanks for the clarification. It really helped.

José Roca

Not the entire textbox, but a buffer enough for the longest line. Anyway, you can use EM_LINELENGTH instead, if you wish, but don't forget MKI$(<length of the buffer>).