TMultiGet:SetSel() and TMultiGet:SetPos() methods

Post Reply
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

TMultiGet:SetSel() and TMultiGet:SetPos() methods

Post by Enrico Maria Giordano »

There is a difference in the selected range between the two methods. Look at this sample:

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    LOCAL oGet

    LOCAL cVar := "This is a test"

    DEFINE DIALOG oDlg

    @ 1, 1 GET oGet VAR cVar MEMO SIZE 100, 30

    @ 3, 1 BUTTON "&Close" ACTION oDlg:End()

    oDlg:bStart = { || oGet:SetSel( 2, 4 ) }
//    oDlg:bStart = { || oGet:SetPos( 2, 4 ) }

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL
You will see that SetSel() selects "is" while SetPos() selects "hi". A possible fix is to change the SetPos() method this way:

Code: Select all

   METHOD SetPos( nStart, nEnd ) INLINE ;
                 nEnd := If( nEnd == nil, nStart, nEnd ),;
                 ::SendMsg( EM_SETSEL, nStart - If( nStart > 0, 0, 0 ), nEnd - If( nEnd > 0, 0, 0 ) ),;
                 ::nPos := nStart
or, of course, completely remove the If().

EMG
Post Reply