On Change ( get ) Incremental Search

On Change ( get ) Incremental Search

Postby Rick Lipkin » Mon Mar 05, 2012 2:26 pm

To All

In Working up my Incremental search Antonio suggested to use On Change on a get to trap the values being typed into a field.

Code: Select all  Expand view  RUN

REDEFINE GET oLname var cLname ID 153 of oFld:aDialogs[1] ;
         ON CHANGE ( _Isearch( oLname, cLname, oLbx, oRsCust )) UPDATE
 


I created a Function to pass and trap the value of the Get ( cLname ) in the function _Isearch().

Code: Select all  Expand view  RUN

//-------------
Static Func  _Isearch( oLname, cLname, oBrw, oRsCust )


cLname := alltrim(cLname )

Msginfo( cLname)  // rem this out and the function will fail


If len( cLname ) = 0
   oRsCust:Filter := ""
   oRsCust:Filter := "[Last Name] = 'bogus'"
   oBrw:ReFresh()
   oLname:SetFocus()
   Return(.t.)
Endif

If len( cLname ) >= 3

   oRsCust:Filter := ""
   oRsCust:Filter := "[Last Name] like '"+cLname+"%'"

   If oRsCust:eof
      MsgInfo( "No Find" )
      oLname:SetFocus()
      Return(.t.)
   Endif

   oBrw:ReFresh()
   oLname:SetFocus()
   SysReFresh()
   Return(.t.)
Endif

oLname:SetFocus()

Return(.T.)
 


I put a few MsgInfo() in to capture the value and lengths of cLname and I do get values and the above code works GREAT ! What is strange .. when you rem out the MsgInfo's .. the code fails to work and the value of cLname never seems to be evaluated.

I have included the complete code and resource .. Click on the button bar for Customer Info then start typing the the Last Name Lipkin and you will see the value of cLname and after len >= 3 .. the browse will fire and the results will be evaluated ..

Go Back and rem out the MsgInfo and you will notice cLname never seems to get evaluated.

Any advice on what I am missing would be appreciated!
Rick Lipkin


See the entire code here :
Code: Select all  Expand view  RUN

// Incremental search

#include "FiveWin.ch"
#Include "Xbrowse.ch"

STATIC oWnd,oBar,lOK,lOk1,oWndChild,oLbx

//-------------
Func Main()

Local catNewDB,xProvider,cFile,aDir,dExe,cDefa,mStart
Local oCn,cSql,oErr,oRsCust,cLOGIN,Saying,xLogin,cRights
Local cTitle,oButt1,oButt2,nYear,nScr1,nScr2,xMessage,cRdd

PUBLIC xCONNECT

lOK  := .F.


//-- get timestamp on .exe //

cFILE := GetModuleFileName( GetInstance() )
aDIR  := DIRECTORY( cFILE )
dEXE  := aDIR[1] [3]

// where .exe started from is default directory //

mSTART := RAT( "\", cFILE )
cDEFA  := SUBSTR(cFILE,1,mSTART-1)

aDIR := NIL
SET DEFA to ( cDEFA )

SET DELETED on
SET CENTURY on
SET 3DLOOK on

nYEAR := ( year( DATE() )-30 )
SET EPOCH to ( nYEAR )

REQUEST DBFCDX
rddsetdefault ( "
DBFCDX" )

nSCR1 := GetSysMetrics(0)
nSCR2 := GetSysMetrics(1)

xPROVIDER := "
Microsoft.Jet.OLEDB.4.0"
xSOURCE   := cDEFA+"
\Rick.mdb"
cRDD      := xPROVIDER+"
-- "+xSOURCE

 // global connection string
xCONNECT := 'Provider='+xPROVIDER+';Data Source='+xSOURCE

If .not. File( cDefa+"
\Rick.mdb" )

   Ferase( cDefa+"
\Rick.mdb" )

   // create the adox object
   Try
      catNewDB := CreateObject("
ADOX.Catalog")
   Catch
      MsgInfo( "
Could not Create ADOX object")
      Return(.f.)
   End try

   // create the table Rick.mdb
   Try
     catNewDB:Create('Provider='+xProvider+';Data Source='+xSource+';Jet OLEDB:Engine Type=5' )
   Catch
     MsgInfo( "
Could not create the table "+xSource )
     Return(.f.)
   End Try

   Try
     oCn  := CREATEOBJECT( "
ADODB.Connection" )
   Catch
     MsgInfo( "
Could not create the ADO object for connection")
   End Try

   TRY
     oCn:Open( xCONNECT )
   CATCH oErr
     MsgInfo( "
Could not open a Connection to Database "+xSource )
     RETURN(.F.)
   END TRY


   cSQL := "
CREATE TABLE CUSTOMER"
   cSQL += "
( "
   cSQL += "
[CUSTOMEREID] char(18) NOT NULL, "
   cSQL += "
[LAST NAME] char(30) NULL, "
   cSQL += "
[FIRST NAME] char(30) NULL, "
   cSQL += "
[MID INIT] char(30) NULL, "
   cSQL += "
[ADDRESS1] char(30) NULL, "
   cSQL += "
[CITY] char(30) NULL, "
   cSQL += "
[STATE] char(30) NULL, "
   cSQL += "
CONSTRAINT PK_USERINFO PRIMARY KEY ( CUSTOMEREID )"
   cSQL += "
)"

   Try
      oCn:Execute( cSQL )
   Catch
      MsgInfo( "
Table CUSTOMER Failed" )
      Return(.f.)
   End try

   oCn:Close()
   oCn := nil

Endif

xLOGIN := UPPER( WNetGetuser() )+space(8) // fivewin
xLOGIN := SUBSTR(xLOGIN,1,8)

oRsCust := TOleAuto():New( "
ADODB.Recordset" )
oRsCust:CursorType     := 1        // opendkeyset
oRsCust:CursorLocation := 3        // local cache
oRsCust:LockType       := 3        // lockoportunistic

// check for very first user

cSQL := "
SELECT * FROM CUSTOMER"
TRY
   oRsCust:Open( cSQL, xCONNECT )
CATCH oErr
   MsgInfo( "
Error in Opening CUSTOMER table here" )
   RETURN(.F.)
END TRY

If oRsCust:eof

   oRsCust:AddNew()
   oRsCust:Fields("
CustomerEid"):Value  := "011111111111111111"
   oRsCust:Fields("
Last Name"):Value    := "Lipkin"
   oRsCust:Fields("
First Name"):Value   := "Richard"
   oRsCust:Fields("
Mid Init"):Value     := "M"
   oRsCust:Fields("
Address1"):Value     := "123 Anywhere"
   oRsCust:Fields("
City"):Value         := "Columbia"
   oRsCust:Fields("
State"):Value        := "SC"
   oRsCust:Update()

   oRsCust:AddNew()
   oRsCust:Fields("
CustomerEid"):Value  := "011111111111111112"
   oRsCust:Fields("
Last Name"):Value    := "Lipinsky"
   oRsCust:Fields("
First Name"):Value   := "Jason"
   oRsCust:Fields("
Mid Init"):Value     := "S"
   oRsCust:Fields("
Address1"):Value     := "123 Arborgate"
   oRsCust:Fields("
City"):Value         := "Columbia"
   oRsCust:Fields("
State"):Value        := "SC"
   oRsCust:Update()

   oRsCust:AddNew()
   oRsCust:Fields("
CustomerEid"):Value    := "011111111111111113"
   oRsCust:Fields("
Last Name"):Value    := "Lipkin"
   oRsCust:Fields("
First Name"):Value   := "Beth"
   oRsCust:Fields("
Mid Init"):Value     := "  "
   oRsCust:Fields("
Address1"):Value     := "123 Lake Murray Blvd"
   oRsCust:Fields("
City"):Value         := "Lexington"
   oRsCust:Fields("
State"):Value        := "SC"
   oRsCust:Update()

   oRsCust:AddNew()
   oRsCust:Fields("
CustomerEid"):Value    := "011111111111111114"
   oRsCust:Fields("
Last Name"):Value    := "Lizzarous"
   oRsCust:Fields("
First Name"):Value   := "Tim"
   oRsCust:Fields("
Mid Init"):Value     := "J"
   oRsCust:Fields("
Address1"):Value     := "456 Broad River"
   oRsCust:Fields("
City"):Value         := "Irmo"
   oRsCust:Fields("
State"):Value        := "SC"
   oRsCust:Update()


Endif

cRIGHTS := "
(RWS)"

xMESSAGE :=  "
User  "+xLOGIN+"    Rights  "+cRIGHTS+        ;
      "
    Default= "+cDEFA+"      Rdd= "+cRDD+            ;
      "
    Revision  "+DTOC(dEXE)+;
      "
 -r"+str(nSCR1,4)+" x "+STR(nSCR2,4)

cTitle := "
Test Incremental Search with ON CHANGE"

DEFINE WINDOW oWnd ;
       TITLE cTITLE  ;
       MENU BuildMenu();
       MDI

DEFINE BUTTONBAR oBar OF oWnd SIZE 65,70 3DLOOK 2007
oBar:SetColor(0)

DEFINE BUTTON oButt1 OF oBar FileName (cDefa+"
\Icons\REQUEST.bmp") , ;
                                      (cDefa+"
\Icons\DREQUEST.bmp"), ;
                                      (cDefa+"
\Icons\DREQUEST.bmp")  ;
MESSAGE "
Customer Information" ;
ACTION _Custview( "
A",oWnd,oButt1,oButt2 ) ;
PROMPT "
Customer Info"


DEFINE BUTTON oButt2 OF oBar FileName (cDefa+"
\Icons\CLOSE.bmp"), ;
                                      (cDefa+"
\Icons\DCLOSE.bmp"),;
                                      (cDefa+"
\Icons\DCLOSE.bmp") ;
MESSAGE "
Close Application" ;
ACTION ( oWnd:End() ) ;
PROMPT "
Quit"


SET MESSAGE OF oWnd     ;
   to xMESSAGE CLOCK 2007

ACTIVATE WINDOW oWnd MAXIMIZED ;
VALID ( IIF( !lOK, ExitPgm(.T.), .F. ))

RETURN( NIL )

//---------------------------
Static FUNCTION BuildMenu()

LOCAL oMENU, cDEFA

cDEFA := SET(7)


MENU oMenu 2007

   menuitem "
Login..."   ;

   MENUITEM "
&About..."

   MENUITEM "
&Quit"          ;
         MESSAGE "
Close this program";
         ACTION oWND:END()

ENDMENU

RETURN( oMenu )


//-----------------------
Static FUNCTION ExitPgm( lCLEAN )

LOCAL lOK3

lOK3  := .F.

IF lCLEAN = .T.
   lOK3 := .T.
   lOK  := .T.
   SET RESOURCES to

ENDIF

RETURN( lOK3 )

//-------------------------------
Static FUNC _Custview( cMODE,oWnd,oBtn1,oBtn2 )


LOCAL SAYING,cDEFA
LOCAL cTITLE
LOCAL oIco,oFld,oCust
LOCAL oRsCust,cSql

lOK1  := .F.

cSQL := "
SELECT * from CUSTOMER order by [Last Name]"

oRsCust := TOleAuto():New( "
ADODB.Recordset" )
oRsCust:CursorType     := 1        // opendkeyset
oRsCust:CursorLocation := 3        // local cache
oRsCust:LockType       := 3        // lockoportunistic

TRY
   oRsCust:Open( cSQL,xCONNECT )
CATCH oErr
   MsgInfo( "
Error in Opening CUSTOMER table" )
   RETURN(.F.)
END TRY

SysReFresh()

cTITLE := "
Customer Maintenance"

DO CASE
CASE cMODE = "
E"
   cTITLE := "
Customer Maintenance  EDIT"
CASE cMODE = "
A"
   cTITLE := "
Customer Maintenance   ADD"
CASE cMODE = "
V"
   cTITLE := "
Customer Maintenance  VIEW"
ENDCASE

oBtn1:Disable()
oBtn2:Disable()


DEFINE WINDOW oWndChild            ;
       MDICHILD                    ;
       FROM 0,0 to 32,100          ;
       OF oWnd                     ;
       TITLE cTITLE

DEFINE DIALOG oCust RESOURCE "
CUSTOMER" of oWndChild


       REDEFINE FOLDEREX oFld ID 109 of oCust PROMPT "
Billing Information", "Service Address";
                DIALOGS "
CUSTVIEW", "SERVVIEW"

       Folder_1( cMode, oWnd, oRsCust, oFld ) // Custview folder


ACTIVATE DIALOG oCust  NOWAIT ;
   ON INIT ( oCust:Move( 0, 0 ));
   VALID(!GETKEYSTATE( 27 ))


ACTIVATE WINDOW oWndChild ;
   ON INIT oWndChild:SetSize( oCust:nWidth, oCust:nHeight, .T. );
   VALID ( IIF( !lOK1, ExitPgm1(.T.,oWndChild,oRsCust,oBtn1,oBtn2), .F. ))


RETURN( NIL )

// ---------- FOLDER-PAGE 1
Static FUNC FOLDER_1( cMode, oWnd, oRsCust, oFld )

Local oLname,cLname


REDEFINE GET oLname var cLname ID 153 of oFld:aDialogs[1] ;
         ON CHANGE ( _Isearch( oLname, cLname, oLbx, oRsCust )) UPDATE

REDEFINE xBROWSE oLBX                ;
         RECORDSET oRsCust           ;
         COLUMNS "
CUSTOMEREID"       ;
         COLSIZES 50                 ;
         HEADERS "
Cust Id"           ;
         ID 172 of oFld:aDialogs[1]  ;
         AUTOCOLS LINES

         ADD oCol TO oLbx AT 1 DATA {|x| x := _ChkName(oRsCust:Fields("
Last Name"):Value,;
                                                   oRsCust:Fields("
First Name"):Value,;
                                                   oRsCust:Fields("
Mid Init"):Value) };
                                                   HEADER "
Last Name or Company" size 190


         ADD oCol TO oLbx AT 2 DATA {|x| x := _ChkAdd(oRsCust:Fields("
Address1"):Value,;
                                                   oRsCust:Fields("
City"):Value,;
                                                   oRsCust:Fields("
State"):Value) };
                                                   HEADER "
Address" size 200


RETURN( nil )

//----------------------------
Static Func _ChkName( cLast,cFirst,cMiddle )

Local cName

cName := substr("
Unk"+space(45),1,45)

If cMiddle = "
"
   If cFirst = "
" .or. empty( cFirst )
      cName = substr( alltrim( cLast)+space(45),1,45)
   Else
      cName := substr(alltrim(cLast)+"
, "+alltrim(cFirst)+space(45),1,45)
   Endif
Else
   If cFirst = "
" .or. empty( cFirst )
      cName = substr( alltrim( cLast)+space(45),1,45)
   Else
      cName := substr(alltrim(cLast)+"
, "+alltrim(cFirst)+" "+;
               alltrim(cMiddle)+space(45),1,45)
   Endif
Endif

Return( cName )


//-------------------------------
Static Func _ChkAdd( cAddress, cCity, cState )

LOCAL cName

cName := if( cAddress = "
" .or. empty( cAddress ), " ", alltrim( cAddress ))+" "+;
         if( cCity = "
" .or. empty( cCity), " ", alltrim(cCity))+" "+;
         if( cState = "
" .or. empty( cState), " ", alltrim(cState))

cName := substr( alltrim( cName ) +space(45),1,45)

Return( cName )

//-------------
Static Func  _Isearch( oLname, cLname, oBrw, oRsCust )

cLname := alltrim(cLname )

Msginfo( cLname) // rem this out and this function does not work

If len( cLname ) = 0
   oRsCust:Filter := "
"
   oRsCust:Filter := "
[Last Name] = 'bogus'"
   oBrw:ReFresh()
   oLname:SetFocus()
   Return(.t.)
Endif

If len( cLname ) >= 3

   Msginfo( cLname )

   oRsCust:Filter := "
"
   oRsCust:Filter := "
[Last Name] like '"+cLname+"%'"

   If oRsCust:eof
      MsgInfo( "
No Find" )
      oLname:SetFocus()
      Return(.t.)
   Endif

   oBrw:ReFresh()
   oLname:SetFocus()
   SysReFresh()
   Return(.t.)
Endif

oLname:SetFocus()

Return(.T.)
//-------------------------------
Static FUNCTION ExitPgm1( lCLEAN,oWndchild,oRsCust,oBtn1,oBtn2 )

LOCAL cDEFA, lOK3

cDEFA := SET(7)

IF lCLEAN = .T.
   lOK1  := .T.

   oRsCust:CLose()
   oWndChild:End()

   oBtn1:Enable()
   oBtn2:Enable()

ENDIF

RETURN( lOK1 )

 // -- end



Code: Select all  Expand view  RUN

CUSTOMER DIALOG 3, 13, 538, 356
STYLE WS_CHILD
FONT 8, "Arial"
{
 CONTROL "", 109, "TFolderex", 0 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 3, 4, 524, 308
}
CUSTVIEW DIALOG 12, 11, 513, 311
STYLE WS_CHILD
FONT 6, "MS Sans Serif"
{
 GROUPBOX "", 196, 2, -2, 213, 304, BS_GROUPBOX
 LTEXT "Company or Last Name", 112, 7, 39, 105, 10, SS_NOPREFIX | WS_GROUP
 EDITTEXT 153, 7, 50, 105, 12, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
 CONTROL "Customer Info", 172, "TXBrowse", 0 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 221, 1, 290, 215
}
SERVVIEW DIALOG 12, 11, 436, 311
STYLE WS_CHILD
FONT 6, "MS Sans Serif"
{
 LTEXT "Company or Last Name", -1, 24, 58, 105, 10, SS_NOPREFIX | WS_GROUP
 EDITTEXT 120, 24, 70, 105, 12, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
}

 
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: On Change ( get ) Incremental Search

Postby Antonio Linares » Mon Mar 05, 2012 4:27 pm

Rick,

Try to replace the MsgInfo() with a call to SysRefresh()

MsgInfo() lets Windows process pending messages, and thats basically what SysRefresh() does
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: On Change ( get ) Incremental Search

Postby Rick Lipkin » Mon Mar 05, 2012 4:43 pm

Antonio

Adding SysRefresh() made no difference :(

Rick

Code: Select all  Expand view  RUN

//-------------
Static Func  _Isearch( oLname, cLname, oBrw, oRsCust )

SysReFresh()

cLname := alltrim(cLname1 )

SysReFresh()
*Msginfo( cLname)
*MsgInfo( len(cLname ))

If len( cLname ) = 0
   oRsCust:Filter := ""
   oRsCust:Filter := "[Last Name] = 'bogus'"
   oBrw:ReFresh()
   oLname:SetFocus()
   Return(.t.)
Endif

If len( cLname ) >= 3

*   Msginfo( cLname )

   oRsCust:Filter := ""
   oRsCust:Filter := "[Last Name] like '"+cLname+"%'"

   If oRsCust:eof
      MsgInfo( "No Find" )
      oLname1:SetFocus()
      Return(.t.)
   Endif

   oBrw:ReFresh()
   oLname:SetFocus()
   Return(.t.)
Endif

oLname:SetFocus()

Return(Nil)

 
Last edited by Rick Lipkin on Tue Mar 06, 2012 3:00 pm, edited 1 time in total.
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: On Change ( get ) Incremental Search

Postby Rick Lipkin » Tue Mar 06, 2012 2:58 pm

Antonio

Please forgive me if I ask for further help .. I am at a loss to figure out what is not working and why I can not evaluate the cLname variable ON CHANGE without stopping the program execution with a Msginfo ?

I Sincerely appreciate your help and advice!

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: On Change ( get ) Incremental Search

Postby Antonio Linares » Tue Mar 06, 2012 4:12 pm

Rick,

My suggestion is to simplify function _Isearch() to have the simplest code there and to check if that makes a difference

I think that if you peform too much work from that function, it may overload ADO, Windows, etc...

MsgInfo() allows Windows to process pending messages but also it makes a "wait" (until you click on it) and that allows to perform pending work.

I am just guessing, as I don't have your app here. If the problem remains, we may connect online using TeamViewer and I may test on your own machine and app :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: On Change ( get ) Incremental Search

Postby Rick Lipkin » Tue Mar 06, 2012 5:36 pm

Antonio

I have tried just about everything to streamline the _Isearch() function including reading the len of the variable and only evaluating the recordset every 2nd and 4th keystrokes..

Compile and type Lipk in the Last Name field to review the results.. un remark out the MsgInfo function ..test .. then rem it out again ..

Here is the code if you would like to compile along with the .rc . Whatever assistance you can offer would be GREATLY Appreciated!

Rick Lipkin

Code: Select all  Expand view  RUN

// Incremental Search

#include "FiveWin.ch"
#Include "Xbrowse.ch"

STATIC oWnd,oBar,lOK,lOk1,oWndChild,oLbx
STATIC cLname,oLname,oFname,cFname,oFontB

//-------------
Func Main()

Local catNewDB,xProvider,cFile,aDir,dExe,cDefa,mStart
Local oCn,cSql,oErr,oRsCust,cLOGIN,Saying,xLogin,cRights
Local cTitle,oButt1,oButt2,nYear,nScr1,nScr2,xMessage,cRdd

PUBLIC xCONNECT

lOK  := .F.


//-- get timestamp on .exe //

cFILE := GetModuleFileName( GetInstance() )
aDIR  := DIRECTORY( cFILE )
dEXE  := aDIR[1] [3]

// where .exe started from is default directory //

mSTART := RAT( "\", cFILE )
cDEFA  := SUBSTR(cFILE,1,mSTART-1)

aDIR := NIL
SET DEFA to ( cDEFA )

SET DELETED on
SET CENTURY on
SET 3DLOOK on

nYEAR := ( year( DATE() )-30 )
SET EPOCH to ( nYEAR )

REQUEST DBFCDX
rddsetdefault ( "
DBFCDX" )

nSCR1 := GetSysMetrics(0)
nSCR2 := GetSysMetrics(1)

xPROVIDER := "
Microsoft.Jet.OLEDB.4.0"
xSOURCE   := cDEFA+"
\Rick.mdb"
cRDD      := xPROVIDER+"
-- "+xSOURCE

 // global connection string
xCONNECT := 'Provider='+xPROVIDER+';Data Source='+xSOURCE

If .not. File( cDefa+"
\Rick.mdb" )

   Ferase( cDefa+"
\Rick.mdb" )

   // create the adox object
   Try
      catNewDB := CreateObject("
ADOX.Catalog")
   Catch
      MsgInfo( "
Could not Create ADOX object")
      Return(.f.)
   End try

   // create the table Rick.mdb
   Try
     catNewDB:Create('Provider='+xProvider+';Data Source='+xSource+';Jet OLEDB:Engine Type=5' )
   Catch
     MsgInfo( "
Could not create the table "+xSource )
     Return(.f.)
   End Try

   Try
     oCn  := CREATEOBJECT( "
ADODB.Connection" )
   Catch
     MsgInfo( "
Could not create the ADO object for connection")
   End Try

   TRY
     oCn:Open( xCONNECT )
   CATCH oErr
     MsgInfo( "
Could not open a Connection to Database "+xSource )
     RETURN(.F.)
   END TRY


   cSQL := "
CREATE TABLE CUSTOMER"
   cSQL += "
( "
   cSQL += "
[CUSTOMEREID] char(18) NOT NULL, "
   cSQL += "
[LAST NAME] char(30) NULL, "
   cSQL += "
[FIRST NAME] char(30) NULL, "
   cSQL += "
[MID INIT] char(30) NULL, "
   cSQL += "
[ADDRESS1] char(30) NULL, "
   cSQL += "
[CITY] char(30) NULL, "
   cSQL += "
[STATE] char(30) NULL, "
   cSQL += "
CONSTRAINT PK_USERINFO PRIMARY KEY ( CUSTOMEREID )"
   cSQL += "
)"

   Try
      oCn:Execute( cSQL )
   Catch
      MsgInfo( "
Table CUSTOMER Failed" )
      Return(.f.)
   End try

   oCn:Close()
   oCn := nil

Endif

xLOGIN := UPPER( WNetGetuser() )+space(8) // fivewin
xLOGIN := SUBSTR(xLOGIN,1,8)

oRsCust := TOleAuto():New( "
ADODB.Recordset" )
oRsCust:CursorType     := 1        // opendkeyset
oRsCust:CursorLocation := 3        // local cache
oRsCust:LockType       := 3        // lockoportunistic

// check for very first user

cSQL := "
SELECT * FROM CUSTOMER"
TRY
   oRsCust:Open( cSQL, xCONNECT )
CATCH oErr
   MsgInfo( "
Error in Opening CUSTOMER table here" )
   RETURN(.F.)
END TRY

If oRsCust:eof

   oRsCust:AddNew()
   oRsCust:Fields("
CustomerEid"):Value  := "011111111111111111"
   oRsCust:Fields("
Last Name"):Value    := "Lipkin"
   oRsCust:Fields("
First Name"):Value   := "Richard"
   oRsCust:Fields("
Mid Init"):Value     := "M"
   oRsCust:Fields("
Address1"):Value     := "123 Anywhere"
   oRsCust:Fields("
City"):Value         := "Columbia"
   oRsCust:Fields("
State"):Value        := "SC"
   oRsCust:Update()

   oRsCust:AddNew()
   oRsCust:Fields("
CustomerEid"):Value  := "011111111111111112"
   oRsCust:Fields("
Last Name"):Value    := "Lipinsky"
   oRsCust:Fields("
First Name"):Value   := "Jason"
   oRsCust:Fields("
Mid Init"):Value     := "S"
   oRsCust:Fields("
Address1"):Value     := "123 Arborgate"
   oRsCust:Fields("
City"):Value         := "Columbia"
   oRsCust:Fields("
State"):Value        := "SC"
   oRsCust:Update()

   oRsCust:AddNew()
   oRsCust:Fields("
CustomerEid"):Value    := "011111111111111113"
   oRsCust:Fields("
Last Name"):Value    := "Lipkin"
   oRsCust:Fields("
First Name"):Value   := "Beth"
   oRsCust:Fields("
Mid Init"):Value     := "  "
   oRsCust:Fields("
Address1"):Value     := "123 Lake Murray Blvd"
   oRsCust:Fields("
City"):Value         := "Lexington"
   oRsCust:Fields("
State"):Value        := "SC"
   oRsCust:Update()

   oRsCust:AddNew()
   oRsCust:Fields("
CustomerEid"):Value    := "011111111111111114"
   oRsCust:Fields("
Last Name"):Value    := "Lizzarous"
   oRsCust:Fields("
First Name"):Value   := "Tim"
   oRsCust:Fields("
Mid Init"):Value     := "J"
   oRsCust:Fields("
Address1"):Value     := "456 Broad River"
   oRsCust:Fields("
City"):Value         := "Irmo"
   oRsCust:Fields("
State"):Value        := "SC"
   oRsCust:Update()


Endif

oFontB  := TFont():New("
Ms Sans Serif",,-6,.F.,.T. ,,,,.F. )
cRIGHTS := "
(RWS)"

xMESSAGE :=  "
User  "+xLOGIN+"    Rights  "+cRIGHTS+        ;
      "
    Default= "+cDEFA+"      Rdd= "+cRDD+            ;
      "
    Revision  "+DTOC(dEXE)+;
      "
 -r"+str(nSCR1,4)+" x "+STR(nSCR2,4)

cTitle := "
Test Incremental Search with ON CHANGE"

DEFINE WINDOW oWnd ;
       TITLE cTITLE  ;
       MENU BuildMenu();
       MDI

DEFINE BUTTONBAR oBar OF oWnd SIZE 65,70 3DLOOK 2007
oBar:SetColor(0)

DEFINE BUTTON oButt1 OF oBar  ;
MESSAGE "
Customer Information" ;
ACTION _Custview( "
A",oWnd,oButt1,oButt2 ) ;
PROMPT "
Customer Info"


DEFINE BUTTON oButt2 OF oBar ;
MESSAGE "
Close Application" ;
ACTION ( oWnd:End() ) ;
PROMPT "
Quit"


SET MESSAGE OF oWnd     ;
   to xMESSAGE CLOCK 2007

ACTIVATE WINDOW oWnd MAXIMIZED ;
VALID ( IIF( !lOK, ExitPgm(.T.), .F. ))

RETURN( NIL )

//---------------------------
Static FUNCTION BuildMenu()

LOCAL oMENU, cDEFA

cDEFA := SET(7)


MENU oMenu 2007

   menuitem "
Login..."   ;

   MENUITEM "
&About..."

   MENUITEM "
&Quit"          ;
         MESSAGE "
Close this program";
         ACTION oWND:END()

ENDMENU

RETURN( oMenu )


//-----------------------
Static FUNCTION ExitPgm( lCLEAN )

LOCAL lOK3

lOK3  := .F.

IF lCLEAN = .T.
   lOK3 := .T.
   lOK  := .T.
   SET RESOURCES to

ENDIF

RETURN( lOK3 )

//-------------------------------
Static FUNC _Custview( cMODE,oWnd,oBtn1,oBtn2 )


LOCAL SAYING,cDEFA
LOCAL cTITLE
LOCAL oIco,oFld,oCust
LOCAL oRsCust,cSql

lOK1  := .F.

cSQL := "
SELECT * from CUSTOMER order by [Last Name]"

oRsCust := TOleAuto():New( "
ADODB.Recordset" )
oRsCust:CursorType     := 1        // opendkeyset
oRsCust:CursorLocation := 3        // local cache
oRsCust:LockType       := 3        // lockoportunistic

TRY
   oRsCust:Open( cSQL,xCONNECT )
CATCH oErr
   MsgInfo( "
Error in Opening CUSTOMER table" )
   RETURN(.F.)
END TRY

SysReFresh()

cTITLE := "
Customer Maintenance"

DO CASE
CASE cMODE = "
E"
   cTITLE := "
Customer Maintenance  EDIT"
CASE cMODE = "
A"
   cTITLE := "
Customer Maintenance   ADD"
CASE cMODE = "
V"
   cTITLE := "
Customer Maintenance  VIEW"
ENDCASE

oBtn1:Disable()
oBtn2:Disable()


DEFINE WINDOW oWndChild            ;
       MDICHILD                    ;
       FROM 0,0 to 32,100          ;
       OF oWnd                     ;
       TITLE cTITLE

DEFINE DIALOG oCust RESOURCE "
CUSTOMER" of oWndChild


       REDEFINE FOLDEREX oFld ID 109 of oCust PROMPT "
Billing Information", "Service Address";
                DIALOGS "
CUSTVIEW", "SERVVIEW"

       Folder_1( cMode, oWnd, oRsCust, oFld ) // Custview folder


ACTIVATE DIALOG oCust  NOWAIT ;
   ON INIT ( oCust:Move( 0, 0 ));
   VALID(!GETKEYSTATE( 27 ))


ACTIVATE WINDOW oWndChild ;
   ON INIT oWndChild:SetSize( oCust:nWidth, oCust:nHeight, .T. );
   VALID ( IIF( !lOK1, ExitPgm1(.T.,oWndChild,oRsCust,oBtn1,oBtn2), .F. ))


RETURN( NIL )

// ---------- FOLDER-PAGE 1
Static FUNC FOLDER_1( cMode, oWnd, oRsCust, oFld )

Local oSay1,oSay2,oSay3,oSay4

cLname := space(50)
cFname := space(50)

REDEFINE SAY oSay1 PROMPT "
Customer Type" ID 110 OF oFld:aDialogs[1] UPDATE
oSay1:SetFont( oFontB )

REDEFINE SAY oSay2 PROMPT "
Customer Id" ID 111 OF oFld:aDialogs[1] UPDATE
oSay2:SetFont( oFontB )

REDEFINE SAY oSay3 PROMPT "
Company or Last Name" ID 112 OF oFld:aDialogs[1] UPDATE
oSay3:SetFont( oFontB )

REDEFINE SAY oSay4 PROMPT "
First Name" ID 113 OF oFld:aDialogs[1] UPDATE
oSay4:SetFont( oFontB )


REDEFINE GET oLname var cLname ID 153 of oFld:aDialogs[1] ;
         ON CHANGE ( _Isearch( oLname, cLname, oLbx, oRsCust )) UPDATE

REDEFINE GET oFname var cFname ID 154 of oFld:aDialogs[1] UPDATE


REDEFINE xBROWSE oLBX                ;
         RECORDSET oRsCust           ;
         COLUMNS "
CUSTOMEREID"       ;
         COLSIZES 50                 ;
         HEADERS "
Cust Id"           ;
         ID 172 of oFld:aDialogs[1]  ;
         AUTOCOLS LINES

         ADD oCol TO oLbx AT 1 DATA {|x| x := _ChkName(oRsCust:Fields("
Last Name"):Value,;
                                                   oRsCust:Fields("
First Name"):Value,;
                                                   oRsCust:Fields("
Mid Init"):Value) };
                                                   HEADER "
Last Name or Company" size 190


         ADD oCol TO oLbx AT 2 DATA {|x| x := _ChkAdd(oRsCust:Fields("
Address1"):Value,;
                                                   oRsCust:Fields("
City"):Value,;
                                                   oRsCust:Fields("
State"):Value) };
                                                   HEADER "
Address" size 200


RETURN( nil )

//----------------------------
Static Func _ChkName( cLast,cFirst,cMiddle )

Local cName

cName := substr("
Unk"+space(45),1,45)

If cMiddle = "
"
   If cFirst = "
" .or. empty( cFirst )
      cName = substr( alltrim( cLast)+space(45),1,45)
   Else
      cName := substr(alltrim(cLast)+"
, "+alltrim(cFirst)+space(45),1,45)
   Endif
Else
   If cFirst = "
" .or. empty( cFirst )
      cName = substr( alltrim( cLast)+space(45),1,45)
   Else
      cName := substr(alltrim(cLast)+"
, "+alltrim(cFirst)+" "+;
               alltrim(cMiddle)+space(45),1,45)
   Endif
Endif

Return( cName )


//-------------------------------
Static Func _ChkAdd( cAddress, cCity, cState )

LOCAL cName

cName := if( cAddress = "
" .or. empty( cAddress ), " ", alltrim( cAddress ))+" "+;
         if( cCity = "
" .or. empty( cCity), " ", alltrim(cCity))+" "+;
         if( cState = "
" .or. empty( cState), " ", alltrim(cState))

cName := substr( alltrim( cName ) +space(45),1,45)

Return( cName )

//-------------
Static Func  _Isearch( oLname1, cLname1, oBrw, oRsCust )

Local nTimes := 0

cLname1 := alltrim(cLname1 )

*Do while nTimes <= 10000000
*   nTimes++
*Enddo

*MsgInfo( len(cLname1 ))

If len( cLname1 ) = 0
 *  MsgInfo( "
zero" )
 *  oRsCust:Filter := "
"
 *  oRsCust:Filter := "
[Last Name] = 'bogus'"
 *  oBrw:ReFresh()
   oLname:SetFocus()
   Return(.t.)
Endif

If len( cLname1 ) = 3 .or. len( cLname1 ) = 5

 *  Msginfo( cLname1 )

   oRsCust:Filter := "
"
   oRsCust:Filter := "
[Last Name] like '"+cLname1+"%'"

   If oRsCust:eof
      MsgInfo( "
No Find" )
      oLname:SetFocus()
      Return(.t.)
   Endif

   oBrw:ReFresh()
   oLname:SetFocus()
   SysReFresh()
   Return(.t.)
Endif

oLname:SetFocus()

Return(.T.)
//-------------------------------
Static FUNCTION ExitPgm1( lCLEAN,oWndchild,oRsCust,oBtn1,oBtn2 )

LOCAL cDEFA, lOK3

cDEFA := SET(7)

IF lCLEAN = .T.
   lOK1  := .T.

   oRsCust:CLose()
   oWndChild:End()

   oBtn1:Enable()
   oBtn2:Enable()

ENDIF

RETURN( lOK1 )

 // -- end


.Rc

Code: Select all  Expand view  RUN

CUSTOMER DIALOG 3, 13, 538, 356
STYLE WS_CHILD
FONT 8, "Arial"
{
 CONTROL "", 109, "TFolderex", 0 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 3, 4, 524, 308
}
CUSTVIEW DIALOG 12, 11, 513, 311
STYLE WS_CHILD
FONT 6, "MS Sans Serif"
{
 LTEXT "Customer Type", 110, 8, 8, 37, 22, SS_NOPREFIX | WS_GROUP
 CONTROL "  Individual   ", 150, "BUTTON", BS_AUTORADIOBUTTON, 46, 10, 63, 12
 CONTROL "  Commercial", 151, "BUTTON", BS_AUTORADIOBUTTON, 46, 24, 63, 12
 CONTROL "Customer Id", 111, "STATIC", SS_CENTER | SS_NOPREFIX | WS_BORDER | WS_GROUP, 112, 11, 94, 10
 EDITTEXT 152, 112, 23, 94, 12, ES_AUTOHSCROLL | NOT WS_TABSTOP | WS_BORDER
 LTEXT "Company or Last Name", 112, 7, 39, 105, 10, SS_NOPREFIX | WS_GROUP
 LTEXT "First Name", 113, 119, 39, 73, 10, SS_NOPREFIX | WS_GROUP
 EDITTEXT 153, 7, 50, 105, 12, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
 EDITTEXT 154, 117, 50, 76, 12, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
 GROUPBOX "", 196, 2, -2, 213, 304, BS_GROUPBOX
 CONTROL "Customer Info", 172, "TXBrowse", 0 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 221, 1, 290, 215
}
SERVVIEW DIALOG 12, 11, 436, 311
STYLE WS_CHILD
FONT 6, "MS Sans Serif"
{
 LTEXT "Company or Last Name", -1, 24, 58, 105, 10, SS_NOPREFIX | WS_GROUP
 EDITTEXT 120, 24, 70, 105, 12, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
}
 
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: On Change ( get ) Incremental Search

Postby Antonio Linares » Tue Mar 06, 2012 10:26 pm

Rick,

Solved :-)

We have to use the text of the GET and not its related variable. With the MsgInfo() it was working as the GET was loosing the focus and that made the variable to be assigned

Code: Select all  Expand view  RUN
Static Func _Isearch( oLname1, cLname1, oBrw, oRsCust )

  cLname1 = Alltrim( oLName1:GetText() )

  if Empty( cLName1 )
     return .T.
  endif  

   oRsCust:Filter := ""
   oRsCust:Filter := "[Last Name] like '"+cLname1+"%'"

   oBrw:ReFresh()

Return .T.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: On Change ( get ) Incremental Search

Postby Antonio Linares » Tue Mar 06, 2012 10:32 pm

You can even remove this:

// oRsCust:Filter := ""

and keeps working fine. I guess that faster :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: On Change ( get ) Incremental Search

Postby Rick Lipkin » Tue Mar 06, 2012 11:03 pm

Antonio

I knew the solution was out of my realm of expertise .. If you like and think the code would make a contribution to the \samples .. it might be a good example on how to utilize the ON CHANGE clause and how to evaluate the value of the Text of the GET.

My Gratitude and Thanks !

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: On Change ( get ) Incremental Search

Postby Antonio Linares » Tue Mar 06, 2012 11:42 pm

Rick,

Thanks for your offer, Yes, I have added it to FWH\samples as it is a very good one :-)

many thanks!
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 87 guests