FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Generic ActiveX methods via OnError
Posts: 20
Joined: Fri Oct 14, 2005 07:56 AM
Generic ActiveX methods via OnError
Posted: Mon Sep 11, 2006 08:01 AM
Antonio:
I'm creating a wrapper class for a commercial ActiveX control.
Rather than code a Method for each function, I created the OnError handler below to attempt to post any unknown message as a call to the actual control. It seems to work, but there are a couple issues:

How can I handle passing non-string args? In PRG code, can I "push items onto the stack" and exec the Do() method?
Is there a better way to do this, or do you see a lurking problem?

METHOD OnError( ... ) CLASS XXXView
static lInErrorAlready := .f.
local cMsg   := __GetMessage(), cCmd, x
private oSelf := Self

   IF lInErrorAlready
      _ClsSetError( _GenError( 1004, ::ClassName(), cMsg  ) )
   ELSE
      lInErrorAlready := .t.
      cCmd := "oSelf:Do('"+ cMsg
      FOR EACH x IN HB_aParams()
          cCmd += "','" + x
      NEXT
      cCmd += "')"
      &cCmd

   ENDIF
   lInErrorAlready := .F.

RETURN nil
-BH
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Generic ActiveX methods via OnError
Posted: Mon Sep 11, 2006 01:07 PM
Brian,

We prefeer to avoid macros, and this way you get it working for any type of parameters (though it is limited to a certain amount of them, but you can increase it to 10 params or more):
METHOD OnError( u1, u2, u3, u4, u5 ) CLASS XXXView 

   static lInErrorAlready := .f. 

   local cMsg := __GetMessage(), uRet

   IF lInErrorAlready 
      _ClsSetError( _GenError( 1004, ::ClassName(), cMsg  ) ) 
   ELSE 
      lInErrorAlready := .t. 
      do case
         case PCount() == 0
               uRet = ::Do( cMsg )

        case PCount() == 1
               uRet = ::Do( cMsg, u1 )

        case PCount() == 2
               uRet = ::Do( cMsg, u1, u2 )

        case PCount() == 3
               uRet = ::Do( cMsg, u1, u2, u3 )

        case PCount() == 4
               uRet = ::Do( cMsg, u1, u2, u3, u4 )

        case PCount() == 5
               uRet = ::Do( cMsg, u1, u2, u3, u4, u5 )

        otherwise
              MsgAlert( "More cases needed" )
     endcase

   ENDIF 
   lInErrorAlready := .F. 

RETURN uRet
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 20
Joined: Fri Oct 14, 2005 07:56 AM
Generic ActiveX methods via OnError
Posted: Mon Sep 11, 2006 08:10 PM

Terrific, Thanks!

-BH
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Generic ActiveX methods via OnError
Posted: Thu Jun 11, 2009 09:15 AM
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion