Announcement

Collapse
No announcement yet.

Array delete on array with objects results in data mismatch

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

  • Array delete on array with objects results in data mismatch

    I have an add method with code like:
    Code:
    ReDim Preserve M_Items( 0 To nIndex )
    M_Items( nIndex ) = Item
    My remove method in the same interface has code like:
    Code:
    Method RemoveAt( ByVal nIndex As Long ) As Long
        Array Delete M_Items( nIndex )
    End Method
    Item is an interface, like i said, it compiles fine if i remove the remove method.
    (Iow, Add() works)

    PowerBASIC for Windows
    PB/Win Version 9.00
    Copyright (c) 1996-2008 PowerBasic Inc.
    Venice, Florida USA
    All Rights Reserved

    Error 482 in ......: Data type mismatch

    Line 1232: Array Delete M_Items( nIndex )
    hellobasic

  • #2
    what if you assign the value of nIndex to a local variable and ARRAY DELETE mitems(localvar)?

    Comment


    • #3
      Hi Edwin,

      I think that I ran into the same problem when I started with the PB Objects. Check out Jose's response at: http://www.jose.it-berater.org/smffo...sg8303#msg8303

      Basically, you need to use INSTANCE when Redimming the array.
      Paul Squires
      FireFly Visual Designer (for PowerBASIC Windows 10+)
      Version 3 now available.
      http://www.planetsquires.com

      Comment


      • #4
        I haven't tested the dim situation but this question is about the deletion of a single item from the array.

        The topic you mention does not show something for deletion.
        It is weird since an array can hold anything.
        hellobasic

        Comment


        • #5
          This compiles & runs OK for me, but try removing the INSTANCE in the REDIM!

          Code:
          #COMPILE EXE
          #DIM ALL
          
          CLASS testclass
           INSTANCE testarray() AS LONG
              INTERFACE test
                  INHERIT IUNKNOWN
              '-----------------------------------------
              METHOD ADD( BYVAL nIndex AS LONG ) AS LONG
                  REDIM PRESERVE test_array( 0 TO nIndex ) AS INSTANCE LONG
                  test_array( nIndex ) = nIndex
              END METHOD
              '---------------------------------------
              METHOD RemoveAt( BYVAL nIndex AS LONG ) AS LONG
                  ARRAY DELETE testarray( nIndex )
              END METHOD
              END INTERFACE
          END CLASS
          '-------------------------------
              GLOBAL x AS test
          '-------------------------------
          FUNCTION PBMAIN () AS LONG
          
              x = CLASS "MytestClass"
          
              ? "done"
          END FUNCTION

          Comment


          • #6
            At first i thought you where right but...

            Change the instance array to:

            Instance testarray() As test

            If you don't trust this, prepare another interface..

            It seems it's really related to arrays holding interfaces.
            hellobasic

            Comment


            • #7
              Hi Edwin,

              I ran into this as well. Seems like a strange limitation but you can get around this by using DIM AT.

              Code:
              dim m_Objects() as IObject
              
              lMin = lbound(m_Objects)
              lMax = ubound(m_Objects)
              redim Index(lMin to lMax) as dword at varptr(m_Objects(lMin))
              
              array delete Index(lDeleteRow)
              Start as you mean to go on.

              Comment


              • #8
                Just to let you know. I reported this to support and they identified it.

                Cheers

                Steven
                So here we are, this is the end.
                But all that dies, is born again.
                - From The Ashes (In This Moment)

                Comment


                • #9
                  Oh, good that this is known to PB.

                  Mark be careful, this situation may not release the object!
                  It remains existing i think.
                  You can test this with method Destroy
                  hellobasic

                  Comment


                  • #10
                    Not entirly tested but i guess i have issues with redim preserve.
                    I think the objects are released and newly created.
                    Not tested but maybe at this time but maybe someone already knows.
                    hellobasic

                    Comment

                    Working...
                    X