Announcement

Collapse
No announcement yet.

Ubound not via pointer to struct!

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

  • Ubound not via pointer to struct!

    I get an error on this.
    it should be possible though..

    Code:
    Type My_Struct
    
        hIcon( 1 To 10 )        As Long
    
    End Type
    
    ''''''''
    
    Dim pMalloc     As My_Struct PTR
    
    For a = Lbound( @pMalloc.hIcon() ) To Ubound( @pMalloc.hIcon() )
    ------------------
    [email protected]
    hellobasic

  • #2
    Edwin

    as far as I know you can't - arrays in TYPEs are not created the
    same way as standard PB arrays - the PB array descriptor is not
    present. If you know what type the array is you can find out
    the number of elements as follows:

    Code:
    Type My_Struct
         hIcon( 0 TO 10 ) AS LONG
    END Type
           
    FUNCTION PBMAIN() AS LONG
       LOCAL tPtr AS My_Struct PTR
       LOCAL lDummy AS LONG
       
       MSGBOX "UBound is " + FORMAT$(SIZEOF(@tPtr) \ SIZEOF(lDummy))
       
       WAITKEY$
    END FUNCTION
    Why not use dynamic structures directly (make the type an array)?

    Cheers

    Florent

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

    Comment


    • #3
      Basically (no pun intended), a UDT is defined at compile time so the effective lower and upper boundaries of an array within a UDT are *known* at compile time.

      This is a perfect place to define these boundaries with numeric equates.

      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Maybe you are right Lance.
        I consider constants..

        Florent,
        The hicon entry is just an entry for this example.
        Other elements where discarded for this example.

        I'll certainly try SIZEOF

        Thanks,

        ------------------
        [email protected]
        hellobasic

        Comment


        • #5
          "Array" was an unfortunate choice of words to use when PB added "tables" to UDTs.

          None of the "ARRAY" verbs work on tables, though in the current releases of the compilers the compilers do not catch it at compile time.

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

          Comment

          Working...
          X