Announcement

Collapse
No announcement yet.

Deleting from an array of objects

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

  • Deleting from an array of objects

    Apparently once you have made and array of objects, you cannot delete a member using ARRAY DELETE.

    This workaround seems to work, but I would appreciate any observations....

    Code:
    '--------------------------------------------------------------------------------
    ' delete the lx'th object from the global array gBX and shuffle the array down, redim to remove topmost member
    sub DeleteObject (lx as long)
        local i, n as long
    
        n = ubound(gBX)
        gBX(lx) = nothing
        for i = lx to n -1
            gBX(i) = gBX(i + 1)
        next
        gBX(n) = nothing
        if n > 0 then
            redim preserve gBX(0 to n-1) as global ICtlBox
        else
            erase gBX()
        end if
    end sub

  • #2
    Hey Chris,

    This is what I do...

    Code:
    dim lMinRow as long
    dim lMaxRow as long
    
    lMinRow = lbound(m_Objects)
    lMaxRow = ubound(m_Objects)
    
    m_Objects(lRow) = nothing
    
    redim Index(lMinRow to lMaxRow) as dword at varptr(m_Objects(lMinRow))
    array delete Index(lRow)
    Start as you mean to go on.

    Comment


    • #3
      Mark, that looks like an index, so the array of interfaces never changes? That would work OK unless you had a great turnover of objects. In fact it would be quite efficient. Thanks!

      BTW I have it on good authority that none of the the ARRAY statements work with interface arrays.

      Comment


      • #4
        Hey Chris,

        Well it's not actually an Index per say...

        The array of objects, "under the hood" is nothing more than an array of DWORDs. So if you allocate an array of DWORDs over top (DIM AT) then you can use ARRAY DELETE to remove that element via the overlapped array.

        Maybe one of the Guru's can confirm this idea so we can both feel better about using it
        Start as you mean to go on.

        Comment


        • #5
          Originally posted by Mark Smit View Post
          The array of objects, "under the hood" is nothing more than an array of DWORDs. So if you allocate an array of DWORDs over top (DIM AT) then you can use ARRAY DELETE to remove that element via the overlapped array
          That will work but this will not reduce the reference count. I would do a arrayofobjs(i)=NOTHING before I did an array delete on it.
          Sincerely,

          Steve Rossell
          PowerBASIC Staff

          Comment


          • #6
            Yup, that was in the example I posted

            Code:
            m_Objects(lRow) = nothing
            Start as you mean to go on.

            Comment


            • #7
              BTW I have it on good authority that none of the the ARRAY statements work with interface arrays
              If that's a design restriction it should be in the help file under ARRAY DELETE.

              It ain't.
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Originally posted by Michael Mattias View Post
                It ain't.
                yet.

                Comment


                • #9
                  That must be a "confirmed" bug. (Yes, a "bug" can be present in the help file)

                  I will no longer be referring to "known" bugs, as none have been placed in the PowerBASE forum and therefore are not known to anyone who could actually use that information to avoid spending ANOTHER hour and half (two such sessions already) trying to make something which never had a chance of working work.

                  Neither the five bugs I have personally found and reported and have been "confirmed" by PB support, nor the twenty more neatly itemized in the 'history.txt' file included with the first 9.0.1 beta release which was sent to me unsolicited should be considered "known."

                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    I am so glad to have found this out before finding this out.
                    Furcadia, an interesting online MMORPG in which you can create and program your own content.

                    Comment


                    • #11
                      The bummer is, you just don't know:

                      Is ARRAY DELETE *not* supported for an array of objects, in which case there are errors in both the help file and the compiler (if not supported, should generate a compile-time error)?

                      Or,

                      Is ARRAY DELETE *supposed* to work with arrays of objects, in which case the bug is ONLY in the compiler?

                      Enquiring minds....yadda yadda...
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Your remarks are not simply disingenuous, they are dead wrong. I hope everyone will disregard this remark from Mr. Mattias as it's false and misleading.

                        Best regards,

                        Bob Zale
                        PowerBASIC Inc.

                        Comment


                        • #13
                          A disingenuous question? That's a new one on me.

                          Given Mr. Holbrook's code - which I have not tried myself, but I trust him - demonstrates that ARRAY DELETE does not delete elements from an array of objects, which is it?

                          Does the help file fail to state and the compiler fail to detect an unsupported use of ARRAY DELETE, or does the compiler simply not generate the correct code to effect an ARRAY DELETE when called?

                          If it's not supported, fine. Just say so.

                          If it's a code-generation error, fine. Just say so.

                          The point is, we - your customers - have no way to know.

                          MCM
                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment


                          • #14
                            What happened when you tried it?

                            (Where have I heard that phrase before?)


                            It's not nice, nor is it productive, to mislead our friends here, so please try to restrain yourself. You comments are dead wrong, so please try to keep them contained?

                            Comment


                            • #15
                              >What happened when you tried it?

                              What happened was, valid ARRAY DELETE syntax was rejected by the compiler, that's what happened.
                              Code:
                              'tarraydelo.bas
                              
                              #COMPILE EXE
                              #DIM ALL
                              #INCLUDE "WIN32API.INC"
                              #INCLUDE   "VBAPI32.INC"       'required as of 11/28/08 (safeArray functions)
                              #INCLUDE   "ADODB28DISP.INC"  ' regenerated with CC5 com browser "dispatch only"
                              
                              GLOBAL gbx() AS Int__Connection
                              
                              FUNCTION PBMAIN () AS LONG
                                  
                               LOCAL I AS LONG, bGoodObjects AS LONG
                                  
                               REDIM  gbx (9)
                               
                               FOR i = 0 TO 9
                                   LET  gbx(I) = NEWCOM $PROGID_ADODB_Connection
                                   IF OBJRESULT <>%S_OK THEN
                                         MSGBOX "Object Creation Failed"
                                         EXIT FUNCTION
                                   END IF
                               NEXT
                               
                               ' test that our objects are good
                               
                               GOSUB TestForGoodobjects
                               
                               ' let's try to delete an element using valid ARRAY DELETE syntax:
                               ARRAY DELETE gbx(5)   ' compiler error: Error 482 datatype mismatch
                               
                               GOSUB TestForGoodObjects
                               
                               
                               EXIT FUNCTION
                                
                               
                              TestForGoodObjects:
                                bGoodObjects = %TRUE
                                FOR I = LBOUND (gbx,1) TO UBOUND (gbx,1)
                                    IF ISFALSE ISOBJECT (gbx(i))  THEN
                                        MSGBOX USING$ ("Bad object at subscript #", i)
                                        bGoodObjects = %FALSE
                                        EXIT FOR
                                    END IF
                                NEXT
                                
                                RETURN
                                        
                                    
                              END FUNCTION
                              Code:
                              PowerBASIC for Windows
                              PB/Win  Version 9.00 
                              Copyright (c) 1996-2008 PowerBasic Inc.
                              Venice, Florida USA
                              All Rights Reserved
                              
                              Error 482 in D:\SOFTWA~1\pbwin80\work\testarraydeleteobject.bas(34:015):  Data type mismatch
                              Line 34:  ARRAY DELETE gbx(5)   ' compiler error: Error 482 datatype mismatch
                              (reported to PB support)
                              Last edited by Michael Mattias; 30 Jan 2009, 03:35 PM.
                              Michael Mattias
                              Tal Systems (retired)
                              Port Washington WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment


                              • #16
                                Please stop misleading the folks. It isn't nice.

                                Comment


                                • #17
                                  Hey Bob,

                                  Am I missing something?

                                  Michael's code example produces the same results on my end? Are you saying that ARRAY DELETE is supposed to work on arrays of objects?

                                  Thanks
                                  Start as you mean to go on.

                                  Comment


                                  • #18
                                    At least one of us is now thoroughly confused.

                                    I'll wait to see what PB Support says.

                                    Oops, I did not send the included file ADODBDISP28.INC, generated by the COM browser. I better resend that. I used the factory-supplied WIN32API.INC and VBAPI.INC files.
                                    Michael Mattias
                                    Tal Systems (retired)
                                    Port Washington WI USA
                                    [email protected]
                                    http://www.talsystems.com

                                    Comment


                                    • #19
                                      No, Mark, PowerBASIC generates a very polite exception report of a DATA TYPE MISMATCH if you try to use any ARRAY statement with an array of objects. Can you just imagine trying to SORT or SCAN an array of objects when the various forms are so deeply intertwined?

                                      Mr. Mattias falsely claimed that no compile-time exception was generated:

                                      "Does the...compiler fail to detect an unsupported use of ARRAY DELETE"

                                      No
                                      "...or does the compiler simply not generate the correct code to effect an ARRAY DELETE when called?"
                                      No

                                      Best regards,
                                      Bob

                                      Comment


                                      • #20
                                        oops!
                                        Last edited by Chris Holbrook; 30 Jan 2009, 05:59 PM. Reason: can't even spell fecking OOPS!

                                        Comment

                                        Working...
                                        X