Page 2 of 4

Re: AutoFill in Text Box

Posted: Sat May 09, 2009 5:49 pm
by Rathinagiri
When pressing back space, it selects left character in stead of deleting it.
Yes. In your previous code, what was the behavior? Left character gets deleted and nothing is selected in the right?

Re: AutoFill in Text Box

Posted: Sat May 09, 2009 7:52 pm
by esgici
Hi All

In appearance this isn't easy task as far as seen at first sight.

Please look and test this version.

Code: Select all

/*
  

  AutoFill in Text Box try

  Started by Esgici
  
  Enhanced by Roberto Lopez and Rathinagiri
  
  2009.05.09
  
*/

#include "minigui.ch"


PROC Main()

   aCountries := HB_ATOKENS( MEMOREAD( "Countries.lst" ),   CRLF )
   
   ASORT( aCountries )                    // This Array MUST be sorted
       
   DEFINE WINDOW frmAFTest ;
      AT 0,0 ;
      WIDTH 550 ;
      HEIGHT 300 ;
      TITLE 'AutoFill in Text Box try' ;
      MAIN 
      
      ON KEY UP     ACTION AutoFill( ThisWindow.Name, "txbCountry",  aCountries, 1 )
      ON KEY DOWN   ACTION AutoFill( ThisWindow.Name, "txbCountry",  aCountries, 2 )
      
      ON KEY ESCAPE ACTION frmAFTest.Release
      
      DEFINE LABEL lblCountry
         ROW        50
         COL        50
         VALUE      "Country :"
         RIGHTALIGN .T.
         AUTOSIZE   .T.
      END LABEL // lblCountry
            
      DEFINE TEXTBOX txbCountry 
         ROW      48
         COL      110
         ONCHANGE AutoFill( ThisWindow.Name, This.Name, aCountries )
      END TEXTBOX // txbCountry   
   
   END WINDOW // frmAFTest
   
   frmAFTest.Center
   
   frmAFTest.Activate

      
RETU // Main()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROC AutoFill( ;              // Auto filling text box
                cFrmName  ,;  // Form / Windows name 
                cTxBName  ,;  // Text Box Name 
                aList,;       // Items list 
                nCaller )     // NIL : OnChange, 1: UP, 2: Down
               
   STATIC cLastVal := '',;
          n1Result := 0
   
   LOCAL  cTxBValue := GetProperty( cFrmName, cTxBName, "Value" ),;     // Text Box Value 
          nCarePos  := GetProperty( cFrmName, cTxBName, "CaretPos" ),;  // Text Box CaretPos
          cCurval   := ''
          
      
   IF HB_ISNIL( nCaller )

      IF !( cLastVal == cTxBValue )    
      
         cCurval  := LEFT( cTxBValue, nCarePos )
         
         IF !EMPTY( cCurval ) 
         
            n1Result := ASCAN( aList, { | c1 | UPPER( LEFT( c1, LEN( cCurval ) ) ) == UPPER( cCurval )} ) 
            
            IF n1Result > 0
               cCurval := aList[ n1Result ]
            ENDIF n1Result > 0
            
         ENDIF !EMPTY( cCurval ) 
         
         cLastVal := cCurval  
         
         AF_Apply( cFrmName, cTxBName, cCurval, nCarePos )     
         
      ENDIF cLastVal # cCurval      
      
   ELSE 
   
      IF n1Result > 0
      
         IF nCaller < 2 
            n1Result -= IF( n1Result > 1, 1, 0 )
         ELSE
            n1Result += IF( n1Result < LEN( aList ), 1, 0 )
         ENDIF   
             
         cCurval := aList[ n1Result ]
               
         cLastVal := cCurval  
         
         AF_Apply( cFrmName, cTxBName, cCurval, nCarePos )     
         
      ENDIF n1Result > 0
      
   ENDIF HB_ISNIL( nCaller )
                            
RETU // AutoFill()   
   
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROC AF_Apply( cFrmName, cTxBName, cValue, nPosit ) 

   SetProperty( cFrmName, cTxBName, "Value", cValue )        
   SetProperty( cFrmName, cTxBName, "CaretPos", nPosit )        
 
   *!!!!!!!!!!!!!!!!!!!!!!!!
   *
   * I don't like this low-level trick ! :( 
   *
   SendMessage( GetControlHandle( cTxBname, cFrmName), 177, LEN( cValue ), nPosit )

RETU // AF_Apply()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
I'm waiting your comments.

PS: Please attention: Sometimes seems nothing changed by seeing text box value not changed. This occurs especially after pressing backspace or delete keys. This is because the result off filling process become identical with previous one.

Regards

--

Esgici

Re: AutoFill in Text Box

Posted: Sat May 09, 2009 8:34 pm
by Rathinagiri
Hi Esgici,

Had u tested my last version here?

IMHO, we can't have a generic UP/DOWN key definitions because, if you define another listbox in this window, you can't scroll that listbox with the UP/DOWN key.

Re: AutoFill in Text Box

Posted: Sat May 09, 2009 8:41 pm
by esgici
Hi Rathi

Yes, tested.

IMHO at this stage adequate working of auto filling process is more important than scope of up-down keys. For localizing instead of global on-key definition will be easy by your method, I thought.

Thanks and regards.

--

Esgici

Re: AutoFill in Text Box

Posted: Sat May 09, 2009 9:02 pm
by Rathinagiri
As you had rightly said, working of the process is more important.

Had you gone through the back space handling too?

Re: AutoFill in Text Box

Posted: Sat May 09, 2009 9:06 pm
by esgici
rathinagiri wrote: Had you gone through the back space handling too?
Didn't you tried ?

Any problem ?

Regards

--

Esgici

Re: AutoFill in Text Box

Posted: Sat May 09, 2009 9:31 pm
by esgici
Hi

IMHO that love-level trick

Code: Select all

SendMessage( GetControlHandle(  ...
is causing some serious problems.

Please extract ( or simply comment ) it in my last code.

It's very last line :

Code: Select all

   SendMessage( GetControlHandle( cTxBname, cFrmName), 177, LEN( cValue ), nPosit )
Regards

--

Esgici

Re: AutoFill in Text Box

Posted: Sun May 10, 2009 3:47 am
by Rathinagiri
Yes. Now it is working perfect. Thanks a lot Esgici.

Re: AutoFill in Text Box

Posted: Sun May 10, 2009 4:41 am
by sudip
Hi Rathi and Esgici,

Thank you very much. Now, everything is fine :) I tested it :D

Yesterday I was busy with formatting my laptop. It's registry was corrupted. And at that time I couldn't understand low level functions. Still now I am very novice in HMG. ;)

Rathi, sorry my friend. I was wrong regarding user interface. I have to learn many things from you :D

With best regards.

Sudip

Re: AutoFill in Text Box

Posted: Sun May 10, 2009 4:44 am
by sudip
rathinagiri wrote:
When pressing back space, it selects left character in stead of deleting it.
Yes. In your previous code, what was the behavior? Left character gets deleted and nothing is selected in the right?
Yes, my friend, it was not currect :)

Regards.

Sudip