Announcement

Collapse
No announcement yet.

What is the proper way to return an object

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

  • What is the proper way to return an object

    I have a property, currently the property returns nothing.


    Property Get MyProp alias "MyProp"() as IDISPATCH

    Property = NOTHING

    End property


    My VBSCRIPT - Reminder - This is called from VBSCRIPT

    Set Foo = this.MyProp

    if Foo = nothing then
    Msgbox "NOTHING"
    else
    Msgbox "SOMETHING"
    end if

    This keeps crashing.. anyone got any ideas?
    Sr. Software Development Engineer and Sr. Information Security Analyst,
    CEH, Digital Forensic Examiner

  • #2
    Try the IsObject or IsNothing functions.

    If IsObject(Foo) Then .....

    If IsNothing(Foo) Then ......
    Paul Squires
    FireFly Visual Designer (for PowerBASIC Windows 10+)
    Version 3 now available.
    http://www.planetsquires.com

    Comment


    • #3
      I am so sorry but I dont see how that will stop vbscript from crashing. As far as I know vbscript doesnt even offer the isobject is isnothing.

      FYI: this doesnt crash when using it in vb..
      Sr. Software Development Engineer and Sr. Information Security Analyst,
      CEH, Digital Forensic Examiner

      Comment


      • #4
        Sorry Thomas, I thought you were testing code in a PB program or DLL because you said "called from VBSCRIPT". I didn't realize that your code was actually in vbscript. I am not a vbscript dude so I can't offer assistance. Good luck!
        Paul Squires
        FireFly Visual Designer (for PowerBASIC Windows 10+)
        Version 3 now available.
        http://www.planetsquires.com

        Comment


        • #5
          I'm not up on COM, but the way I've been returning an object to another object is with its interface name.
          PB object to PB object
          Code:
                  Property Get FileMemoryManager() As FMemMangI
                      'internal use
                      Property = mMem 'FMemMangI object
                  End Property
          passed to another class, which uses it to to set an object in another class
          Code:
              Class Method Create()
                  mLStack = Class "FLStackC"
                  mStr = Class "FStr16C"
                  If IsObject(mLStack) And IsObject(mStr) Then
                      Local temp As FMemMangI
                      temp = mLStack.FileMemoryManager
                      mStr.Initiate(temp)
                  End If
              End Method
          stanthemanstan~gmail
          Dead Theory Walking
          Range Trie Tree
          HLib ~ Free Data Container Lib ~ Arrays, Lists, Stacks, Queues, Deques, Trees, Hashes

          Comment


          • #6
            Stanley,

            have you tried calling this via VBScript?
            Sr. Software Development Engineer and Sr. Information Security Analyst,
            CEH, Digital Forensic Examiner

            Comment


            • #7
              no
              stanthemanstan~gmail
              Dead Theory Walking
              Range Trie Tree
              HLib ~ Free Data Container Lib ~ Arrays, Lists, Stacks, Queues, Deques, Trees, Hashes

              Comment


              • #8
                Originally posted by Thomas Tierney View Post
                As far as I know vbscript doesnt even offer the isobject is isnothing.
                VBScript offers a IsObject function:

                IsObject Function
                Returns a Boolean value indicating whether an expression references a valid Automation object.

                IsObject(expression)

                The expression argument can be any expression.

                Remarks
                IsObject returns True if expression is a variable of Object subtype or a user-defined object; otherwise, it returns False.

                The following example uses the IsObject function to determine if an identifier represents an object variable:

                Code:
                Dim MyInt, MyCheck, MyObject
                Set MyObject = Me
                MyCheck = IsObject(MyObject)   ' Returns True.
                MyCheck = IsObject(MyInt)   ' Returns False.
                Im not sure though if this works in your situation, as you want to test the state/value of an object's property. It might always return True as long as "this" from your example is a valid object, regardless of the value of MyProp.

                You might try ...
                Code:
                If this.MyProp Is Nothing Then
                   Msgbox "- Nothing"
                Else
                   Msgbox "+ Something"
                End If
                ... instead.
                Last edited by Knuth Konrad; 11 Aug 2009, 11:24 AM.

                Comment


                • #9
                  Why should I change acceptable programming practice?

                  the problem isnt VBScript checking for nothing (IE if x is nothing then)

                  The problem is returning the object from a PB COM component.. very curious
                  Sr. Software Development Engineer and Sr. Information Security Analyst,
                  CEH, Digital Forensic Examiner

                  Comment


                  • #10
                    >The problem is returning the object from a PB COM component.. very curious

                    Granted I am new at this COM stuff, but that is not terribly clear from your post. From Racine Wisconsin it looks like this an an 'All VB-Script' thing!

                    Code shown incomplete and devoid of identification.

                    First thing I think you should do is write yourself a little PB test program to verify the object is being created correctly. Then if you can't get at it from your VB Script, you'll know the problem is NOT with your COM component and you can devote your time and energy to a tree which could actually bear fruit.
                    Last edited by Michael Mattias; 12 Aug 2009, 09:02 AM.
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Michael,

                      I wasn't asking for directions on how to do it. I was wondering what the proper way to do it in PB was. Do I need to return an IUnknown or IDispatch etc.
                      From the posts I dont see that working with vbscript is being done by alot of people so they probably dont have the issues I am seeing. Granted you do not know alot about COM but it should work the same in PB/VB/VBScript/C++ and any number of languages that can use COM. Its a standard really and should be abstracted out from its implentation.
                      The code in my original post should be enough to determine whether or not I am passing the object back to the caller properly, whether the object is null or not is really irrelevant. I should be able to do the check from VBScript. If I am then I will bundle up my code and send it to PB Support where they do, from what I understand, have "COM People".
                      I already know, since it works in VB, that this is a PB issue with VBScript, not a VBScript issue with PB.
                      Sr. Software Development Engineer and Sr. Information Security Analyst,
                      CEH, Digital Forensic Examiner

                      Comment

                      Working...
                      X