Generic ActiveX methods via OnError

Generic ActiveX methods via OnError

Postby Brian Hays » Mon Sep 11, 2006 8: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?

Code: Select all  Expand view
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
Brian Hays
 
Posts: 20
Joined: Fri Oct 14, 2005 7:56 am

Postby Antonio Linares » Mon Sep 11, 2006 1: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):
Code: Select all  Expand view
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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Brian Hays » Mon Sep 11, 2006 8:10 pm

Terrific, Thanks!
-BH
Brian Hays
 
Posts: 20
Joined: Fri Oct 14, 2005 7:56 am

Re: Generic ActiveX methods via OnError

Postby Antonio Linares » Thu Jun 11, 2009 9:15 am

regards, saludos

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: wartiaga and 92 guests