Announcement

Collapse
No announcement yet.

Run Time Error using string pointers

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

  • Run Time Error using string pointers

    While playing with pointers, I constructed the following program,
    more or less from HELP files, that appears to be correct. When
    executed without the MSGBOX statement it terminates without a
    problem. No error occurs. When the MSGBOX line is retained, it
    seems to provide the correct answer (evidence the program is
    correct?), but when the MSGBOX button is clicked a memory
    violation error occurs. Is this a compiler bug, or is the
    program's use of pointers incorrect.

    My PC is a PII system using Windows NT4.0+SP6.
    ------------------------------------------------------------------
    $COMPILE EXE
    FUNCTION PBMAIN() AS LONG
    DIM R(1:4) AS STRING
    R(1)=" String I. ":R(2)=" String II. "
    R(3)=" String III. ":R(4)=" String IV. "

    DIM xptr(1:4) AS STRING PTR
    FOR i&=1 TO 4:xptr(i&)=VARPTR(R(i&)):NEXT

    FOR i&=1 TO 4:x$=x$+@xptr(i&)+"|":NEXT
    MSGBOX x$ ' without this statement no memory access error occurs
    END FUNCTION

  • #2
    Move the dimension for the pointer and it works, go figure.

    Code:
    $Compile Exe
    Option Explicit
    Function PbMain() As Long
    Dim X As String
    Dim I As Long
    Dim xPtr(1 To 4) As String Ptr
    Dim R(1 To 4) As String
    
    R(1) = " String I. "
    R(2) = " String II. "
    R(3) = " String III. "
    R(4) = " String IV. "
    
    For I = 1 To 4
      xPtr(i) = VarPtr(R(i))
    Next
    
    For I = 1 To 4
      X = X & @xPtr(i) & "|"
    Next
    MsgBox X
    End Function
    Curious, I hate it when that happens.

    Chuck

    Comment


    • #3
      I cannot duplicate Joe's problem with either PB/DLL 5.0 nor PB/DLL 6.0.

      Joe, what version of PB/DLL are you using, and what is the date of your PBDLL.EXE file?



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

      Comment


      • #4
        I saw Lance message and decided to test Joe' information (Win98SE, PB/DLL-6).
        I started from IDE first time and saw correct data in Msgbox.
        Started the second time - GPF. Third time - PC simply had hanged.
        I rebooted system and repeat experiment. Approximately the same.

        Clear, that happends something not controlled and these statements destroy a memory.

        Lance, perhaps, you tested under Win2000 ?

        PS. I saw Jim's message. I have IDE Iomega Zip and special driver for electronic keys (LPT)

        [This message has been edited by Semen Matusovski (edited January 31, 2000).]

        Comment


        • #5
          I get the problem with my PC at work NT SP4 IBM 300XL 128 Meg Ram.
          I am running Iomega Parrallel port drivers. I sometimes think they cause
          some memory errors. ( I usually get them when the drives are being read
          by explorer.
          The error on the first program is
          The instruction at 0x00000005 referenced memory at 0x00000005.
          The memory could not be read.
          I don't get this on the second program.
          I am running PBDll 6.0.



          [This message has been edited by Jim Padgett (edited January 31, 2000).]
          Warped by the rain, Driven by the snow...

          jimatluv2rescue.com

          Comment


          • #6
            Lance,

            I compliled Joe's program in PB/DLL6. Works just fine as you said. I am
            using NT4.0 sp6.

            Cecil

            Comment


            • #7
              The original test program runs repeatedly without errors on my NT4 SP3 system. But it produces an Invalid Page Fault the first time it is run on Windows 98.

              -- Eric


              -------------
              Perfect Sync: Perfect Sync Development Tools
              Email: mailto:[email protected][email protected]</A>

              "Not my circus, not my monkeys."

              Comment


              • #8
                My PBDLL.EXE is dated 7/01/99 201,014 bytes in length.

                Comment


                • #9
                  Hi,

                  PBDLL Date: 08.10.1997 (DD.MM.YYYY)
                  Using windows 98 it produces a page fault GPF.



                  -------------
                  Kev G Peel
                  KGP Software
                  Bridgwater, UK.
                  mailto:[email protected][email protected]</A>

                  Comment

                  Working...
                  X
                  😀
                  🥰
                  🤢
                  😎
                  😡
                  👍
                  👎