Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Yes, You CAN Redim Arrays Via A Ptr To Their Descriptor...

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

  • Eric Cochran
    replied
    so as not to have a discussion in the source code forum...

    http://www.powerbasic.com/support/pb...ad.php?t=16951

    ------------------
    software: win xp pro sp 2, pb/win 7.04, pb/cc 4.02, win32api.zip v.02-01-05
    hardware: amd athlon 64 3200+ (clock speed 2.00 ghz) on a gigabyte k8n pro nforce3-150 mobo, 1 gb pc3200/ddr400 ram, geforce 5 le 128 mb ddr video

    Leave a comment:


  • Greg Turgeon
    replied
    before anyone makes the mistake of relying on a tactic like this, here are two statements to keep in mind.

    from bob:
    powerbasic assembler syntax does not support a way to obtain the address of the array descriptor (because the array descriptor contents are not documented, because they may be subject to change in the future).
    http://www.powerbasic.com/support/pb...ad.php?t=20142


    and lance:
    powerbasic has never said that the [internal] array descriptor table would never change, and as discussed above, it is necessary when adding those new features y'all take great care in asking us to build into the language. this is one reason that powerbasic added in the arrayattr() function in pb/win 7.0 and pb/cc 3.0 -- so that arrays could be examined without having to deal with the internal descriptor structure.
    http://www.powerbasic.com/support/pb...ead.php?t=7445


    ------------------

    Leave a comment:


  • Yes, You CAN Redim Arrays Via A Ptr To Their Descriptor...

    ...and here's how. I looked around for how to do this, before, and couldn't seem to find anything. I was doing some late night tinkering, and somehow managed to figure this out. Hope it helps everybody.

    Code:
    #compile exe
    #dim all
    
    type myType
        pString as string ptr     'pString = ptr->string (string array descriptor, here)
    end type
    
    sub resizeIt( _               'Just a sub to demonstrate redim'ing...
        byref test() as string, _ ' PB wants a pointer to the descriptor
        newSize as dword )
        
        redim test( newSize )               'Works like a champ.    [img]http://www.powerbasic.com/support/forums/smile.gif[/img]
    end sub
    
    function pbmain () as long
    
        redim stringData ( 5 ) as string
        local this as myType
        this.pString = varptr( stringData() ) 'Normally you'd probably want to point
                                              'to individual elements, but here we
                                              'just want the descriptor's address.
        #if %def(%pb_cc32)
            print ubound( stringData() )
        #else
            MSGBOX ubound( stringData() )
        #endif
    
    
        resizeIt( byval this.pString, 10 ) 'It's VERY important that you pass the ptr
                                           'to the descriptor byval in order to dodge
                                           'a parameter mismatch error
        #if %def(%pb_cc32)
            print ubound( stringData() )
        waitkey$
        #else
            MSGBOX ubound( stringData() )
        #endif
    end function

    ------------------
    Software: Win XP Pro SP2, PB/Win 7.04, PBCC 4.02, PB Forms 1.5, Win32API.zip v.02-01-05
    Hardware: AMD Athlon 64 3200+ (Clock speed 2.00 GHz) on a Gigabyte K8N Pro nForce3-150 mobo, 1 GB PC3200/DDR400 RAM, GeForce 5 LE 128 MB DDR video



    [This message has been edited by Eric Cochran (edited November 03, 2005).]
Working...
X