BlackTDN Search

sábado, 5 de julho de 2014

BlackTDN :: Harbour CodeBlock

Observe o fragmento de código abaixo e deleite-se com uma das maravilhas da evolução da sintaxe xBase no Harbour: O CodeBlock é, de fato, um CodeBlock.

   1: METHOD start( xAction, ... ) CLASS THREAD
   2:  
   3:    IF ::active
   4:       RETURN .F.
   5:  
   6:    ELSE
   7:       ::pThreadID := hb_threadStart( HB_THREAD_INHERIT_PUBLIC, ;
   8:             {| ... |
   9:                LOCAL nTime
  10:  
  11:                ThreadObject( Self )
  12:  
  13:                ::active := .T.
  14:                ::startCount++
  15:  
  16:                IF HB_ISNUMERIC( ::startTime )
  17:                   nTime := ::startTime - Seconds()
  18:                   IF nTime < 0
  19:                      nTime += 86400
  20:                   ENDIF
  21:                   hb_idleSleep( nTime )
  22:                   ::startTime := NIL
  23:                ENDIF
  24:  
  25:                ::atStart( ... )
  26:                IF HB_ISBLOCK( ::_atStart )
  27:                   Eval( ::_atStart, ... )
  28:                ENDIF
  29:  
  30:                WHILE .T.
  31:  
  32:                   nTime := hb_MilliSeconds()
  33:  
  34:                   BEGIN SEQUENCE
  35:                      IF ! Empty( xAction ) .AND. ValType( xAction ) $ "CBS"
  36:                         ::result := Do( xAction, ... )
  37:                      ELSE
  38:                         ::result := ::execute( ... )
  39:                      ENDIF
  40:                   ALWAYS
  41:                      __QuitCancel()
  42:                   ENDSEQUENCE
  43:  
  44:                   nTime := Int( ( hb_MilliSeconds() - nTime ) / 10 )
  45:                   ::deltaTime := nTime
  46:  
  47:                   /* TODO: when ::startTime is set execution is suspended
  48:                    *       but I do not know the exact conditions and how
  49:                    *       it can be resumed
  50:                    */
  51:  
  52:                   IF ! HB_ISNUMERIC( ::interval )
  53:                      EXIT
  54:                   ENDIF
  55:  
  56:                   nTime := ::interval - ::deltaTime
  57:                   IF nTime > 0
  58:                      hb_idleSleep( nTime / 100 )
  59:                   ENDIF
  60:                   ::startCount++
  61:  
  62:                ENDDO
  63:  
  64:                ::atEnd( ... )
  65:                IF HB_ISBLOCK( ::_atEnd )
  66:                   Eval( ::_atEnd, ... )
  67:                ENDIF
  68:                ::active := .F.
  69:  
  70:                RETURN NIL
  71:             }, ... )
  72:  
  73:       ::threadID := IIF( ::pThreadID == NIL, 0, hb_threadID( ::pThreadID ) )
  74:  
  75:    ENDIF
  76:  
  77: RETURN .T.

[]s
иαldσ dj

Nenhum comentário:

Postar um comentário