Announcement

Collapse
No announcement yet.

PBWin 10: calling an interface method from inside an event class method

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBWin 10: calling an interface method from inside an event class method

    If we have a NEWCOM Object created with an interface(INHERIT IDISPATCH) with one or more methods, and an Event class(INEHRIT IDISPATCH) that belong to the same object:
    linked by "EVENT FROM inteface CALL EventClass"
    How can we CALL an interface method from a method inside the Event class?? What is the correct syntax to do that
    N.B.: The GUIDs of both interface and event class are created beforehand
    ,e.g.

    INTERFACE IGetByte $IID_MyObject_ByteConverter
    INHERIT IDISPATCH

    METHOD GetByte <22> (Source AS VARIANT, Length AS LONG) AS STRING
    .
    .
    .
    END INTERFACE

    .
    .
    .


    CLASS Class_Process $CLSID_MyObject_Event AS EVENT


    INTERFACE ObjEvents $IID_ObjtEvents
    INHERIT IDISPATCH


    METHOD FlagChanged <32> (BYVAL iFlag AS INTEGER)
    '>>>>>>'HERE How can we call GetByte from $IID_MyObject_ByteConverter ????
    "WHAT is the Syntax to do so???
    'Could it be: IGetByte.GetByte which I know is incorrect??

    END METHOD
    .
    .
    .

    END INTERFACE

    Can anybody help??

  • #2
    You could pass the IGETBYTE object as an argument when you RAISE the event making all its properties and methods accessible to your program from within the event code.



    Comment


    • #3
      Thanks for your response ..but How could I make an object an argument to its own event handler? Do I pass it as a parameter to the event class or to the event interface?.because the event is supposed to be raised automatically as the object methods are called and I can not RAISEEVENT it. Can you show me by code ??
      I passed it as: FlagChanged <32> (BYVAL iFlag AS INTEGER,xGetByte as IGetByte) but the program crashed.
      then called it as: xGetByte.GetByte(sData, leng )
      Regards
      Last edited by Jassim Mohammad Kareem; 2 May 2017, 06:02 PM.

      Comment


      • #4
        but How could I make an object an argument to its own event handler?
        Heck, it works in ADO, so I figure you can do something like that in PB. (generate the PB #INCLUDE using the COM browser for ADO and you'll see what I mean. I also know it works.. but was not terribly useful to me. I don't feel like hunting for the PB code which does it, but I will if you think it will help).

        I am assuming you want to 'RAISEEVENT' whilst processing in the interface... and in that case see the ME pseudo-object in the doc to pass 'myself' as an argument to my own event handler.

        If you are trying to RAISEEVENT from *outside* the interface, I think that is misusing interfaces and the owning classes. .

        Comment


        • #5
          .because the event is supposed to be raised automatically as the object methods are called and I can not RAISEEVENT it.
          Huh?

          "Automatically" when you are creating the class/interface code means you have code executing a RAISEEVENT statement.

          Comment


          • #6
            Add a method to the event class, e.g. METHOD ClassObject (BYVAL pObj as IGetByte), an instance variable to store it, e.g. INSTANCE m_pObj AS IGetByte, and call this method after you create the class and before you call EVENTS FROM. In the DESTRUCTOR of the class set m_pObj = NOTHING.
            Forum: http://www.jose.it-berater.org/smfforum/index.php

            Comment


            • #7

              Would a 'GLOBAL m_pObj AS IGetByte' , placed before the event class, expose that object (interface) methods inside the event class so that they can be called there , i.e.

              INTERFACE IGetByte $IID_MyObject_ByteConverter
              INHERIT IDISPATCH

              METHOD GetByte <22> (Source AS VARIANT, Length AS LONG) AS STRING
              .
              .
              .
              END INTERFACE

              .
              'Added

              ENUM EnumSomeConstants

              cNotYet=0
              .
              .
              cDoItNow = 8
              .
              .
              END ENUM


              GLOBAL m_pObj as IGetByte
              .
              .

              CLASS Class_Process $CLSID_MyObject_Event AS EVENT


              INTERFACE ObjEvents $IID_ObjtEvents
              INHERIT IDISPATCH


              METHOD FlagChanged <32> (BYVAL iFlag AS INTEGER)
              'Added just as an example

              Dim Src As VARIANT
              Dim lngLen As Long
              Dim strResult As STRING
              if iFag=%EnumSomeConstants.cDoItNow then
              'The call of the object method comes here
              strResult=m_pObj.GetByte(Src, lngLen)
              ?StrResult
              End if

              END METHOD
              .
              .
              .

              END INTERFACE
              Last edited by Jassim Mohammad Kareem; 3 May 2017, 02:13 AM.

              Comment


              • #8
                Yes.

                From he help file:

                Global variables are accessible from anywhere in your program. They are initialized when your program starts and are destroyed when the program ends.
                Forum: http://www.jose.it-berater.org/smfforum/index.php

                Comment

                Working...
                X