Page 1 of 1

May I have an sample for TProgress for Index

Posted: Sat Sep 29, 2007 6:43 pm
by dutch
Dear All,

I've used TMeter for index progress bar and it works in 16bits but I convert to 32bits now. I don't work properly. May I have an example for Index Progress Bar?

Thanks in advance,
Dutch

Posted: Sat Sep 29, 2007 7:06 pm
by driessen
Sorry, I don't have an example for an index progress bar.

But it looks strange to me that TMeter isn't working in 32-bit.

I converted a progress bar, using TMeter, from 16-bits to 32-bits too and it is working fine here.

Re: May I have an sample for TProgress for Index

Posted: Sat Sep 29, 2007 8:10 pm
by Enrico Maria Giordano
This is a working sample:

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg, oMtr

    LOCAL nPos

    USE TEST

    DEFINE DIALOG oDlg

    @ 1, 1 METER oMtr VAR nPos TOTAL LASTREC();
           SIZE 100, 20

    @ 3, 1 BUTTON "Start";
           ACTION STARTINDEX( oMtr )

    ACTIVATE DIALOG oDlg;
             CENTER

    CLOSE

    RETURN NIL


STATIC FUNCTION STARTINDEX( oMtr )

    INDEX ON FIELD -> last + FIELD -> first TO MTRTEST EVAL ( oMtr:Set( RECNO() ), oMtr:Refresh(), .T. )

    MSGINFO( "Done!" )

    RETURN NIL
EMG

Posted: Wed Oct 03, 2007 5:34 pm
by dutch
Dear Enrico,

Your sample is working as my 16 bits but the difference is RDD but when I use ADS, the index run fine but the Meter is not working.

I use xHarbour.com + FWH7.07 + ADS and it seem the EVAL and EVERY is working properly for ADS.

Thanks,
Dutch

Posted: Wed Oct 03, 2007 6:25 pm
by James Bott
Dutch,

You can't use functions in ADS indexes. ADS is client/server and the server cannot evaluate a function that is inside the client program.

James

Posted: Wed Oct 03, 2007 6:57 pm
by dutch
Dear James,

Thank you very much for kick a mountain out of my head. I waste two days for fixing it.

Regards,
Dutch

Posted: Fri Oct 05, 2007 3:43 am
by hua
Dutch, to show progress meter while indexing via RDDADS, use something similar to the following:

Code: Select all

FUNCtion CreateIndex( aNtxKey )

     LOCAL nCnt, lUnique

     #define ADS_ABORT    .t.
     #define ADS_CONTINUE .f.
     oNtxMeter:nTotal:=100 //LastRec()
     ADSRegCallBack({|nPercent| progress(nPercent,cNtxName)})

     FOR nCnt := 1 TO LEN( aNtxKey )

         cNtxKey  := aNtxKey[ nCnt, 1 ]
         cNtxName := aNtxKey[ nCnt, 2 ]
         cNtxFor := ""
         if len(aNtxKey[nCnt]) > 3
            cNtxFor := aNtxKey[ nCnt, 4 ]
         endif
         lUnique  := if( LEN( aNtxKey[ nCnt ] ) > 2, aNtxKey[ nCnt, 3 ], FALSE  )
         oSayText:bGet := { || "Re-building ... " + UPPER( cNtxName ) + ".NTX" }
         oSayText:Refresh()
         oNtxMeter:Set(0)
         oNtxMeter:display()

         CursorWait()

         IF lUnique
            /*
            if lExclDel
             INDEX ON &( cNtxKey ) TO ( cNtxName )  UNIQUE for !deleted() ;
                EVAL ( oNtxMeter:Set( Recno() ), SysRefresh(), .T. )
            else
            */
             INDEX ON &( cNtxKey ) TO ( cNtxName )  UNIQUE
                //EVAL ( oNtxMeter:Set( Recno() ), SysRefresh(), .T. )
                // ADS doesn't recognize eval..every
            *endif
         ELSE
            if empty(cNtxFor)
               INDEX ON &( cNtxKey ) TO ( cNtxName )
                 //EVAL ( oNtxMeter:Set( Recno() ), SysRefresh(), .T. )
            else
               INDEX ON &( cNtxKey ) TO ( cNtxName ) for &(cNtxFor)
                //EVAL ( oNtxMeter:Set( Recno() ), SysRefresh(), .T. )
            endif
         ENDIF
     NEXT
     ADSClrCallBack()
RETURN (Nil)
//-------------------------------------------------------------------------
static function progress(nPercent,CurrentNtx)
  static cNtx
  if cNtx==nil
     cNtx := ""
  endif
  if empty(cNtx)
     cNtx := currentNtx
  elseif cNtx != CurrentNtx
     cNtx := currentNtx
     oNtxMeter:Set(100)
     oNtxMeter:display()
  endif

  oNtxMeter:Set( nPercent )
  oNtxMeter:display()
return ADS_CONTINUE

Posted: Fri Oct 05, 2007 3:37 pm
by kokookao2007
Hi hua:

Great !!

It work for ADS RDD .

Best Regards

kokoo

Posted: Fri Oct 05, 2007 3:50 pm
by R.F.
That's the way it works !!!!!

Why ?.... well, the explanation is very simple, ADS server does the indexing, not your program, this means that INDEX ON just send the indexing order to the server and then the server takes care of performing the operation, so your program will never know the status of the indexing progress, since you don't have a way of "asking" the ADS server the percentage of advance.

AdsClrCallBack() does a "call back" to the server, this means that the server will give your application an "status" of the currently running process.

The "call back" is only available for indexing, not for running queries (ADS does SQL queries and they are damn fast), or setting AOF() or Scopes.

Posted: Fri Oct 05, 2007 5:24 pm
by dutch
Thanks Hua&Rene&James,

It works well for ADS.

Regards,
Dutch