[futurebasic] Re: Using a Handle (Toolbox call to DAM)

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 1998 : Group Archive : Group : All Groups

From: Jay Reeve <jktr@...>
Date: Tue, 4 Aug 98 21:45:21 +0100
Subject:     Re: [FB] Using a Handle (Toolbox call to DAM)
Sent:        8/4/98 9:30 PM
To:          Thomas Peters, tpeters@...

>LOCAL FN getVChar
>  gCountItems% = gCountItems% + 1
>  LONG IF myResultRecord.gItemType& = _TypeVChar
>    myHandle& = FN NEWHANDLE _clear (myResultRecord.gItemLength% + 2)
>    LONG IF myHandle& AND (SYSERROR = _noErr)
>      osErr% = FN HLOCK (myHandle&)
>      LONG IF osErr% = _noErr
>        Err% = FN dbGetItem% (mySessionRecord.gSessionID&, 60,
>myResultRecord.gItemType&, myResultRecord.gItemLength%,
>myResultRecord.gItemPlaces%, myResultRecord.gItemFlag%, [myHandle&], _nil)
>        osErr% = FN HUNLOCK (myHandle&)
>        LONG IF (Err% = _rcDBValue) OR (Err% = _noErr)
>          BLOCKMOVE [myHandle&], [myHandle&] + 2,
>myResultRecord.gItemLength%
>          POKE LONG @myHandle&, myResultRecord.gItemLength%
>          theText$ = CHR$(39) + PSTR$([myHandle&]) + CHR$(39)
>          FN displayResults (theText$)
>        XELSE
>          BEEP
>          theText$ = STR$(Err%)
>        END IF
>      END IF
>      IF myHandle& <> _nil THEN osErr% = FN DISPOSHANDLE(myHandle&)
>      myHandle& = _nil
>    END IF
>  END IF
>END FN = Err%

Tom, 

Your POKE LONG statement effectively replaces your handle with a string 
length. If your string length is 36, then when your code goes to use the 
handle to get a pointer, it is going to look at memory location 36 to 
find it. Oops.

Try this:

LOCAL FN getVChar
  INC(gCountItems%)
  LONG IF myResultRecord.gItemType& = _TypeVChar
    theLength% = myResultRecord.gItemLength%
    theLength% > 255 then theLength% = 255
    myHandle& = FN NEWHANDLE (theLength% + 1)
    LONG IF myHandle& AND (SYSERROR = _noErr)
      osErr% = FN HLOCK (myHandle&)
      LONG IF osErr% = _noErr
        Err% = FN dbGetItem% (mySessionRecord.gSessionID&, 60,
myResultRecord.gItemType&, theLength%,
myResultRecord.gItemPlaces%, myResultRecord.gItemFlag%, [myHandle&]+1, 
_nil)
        osErr% = FN HUNLOCK (myHandle&)
        LONG IF (Err% = _rcDBValue) OR (Err% = _noErr)
          POKE [myHandle&], theLength%
          theText$ = CHR$(39) + PSTR$([myHandle&]) + CHR$(39)
          FN displayResults (theText$)
        XELSE
          BEEP
          theText$ = STR$(Err%)
        END IF
      END IF
      IF myHandle& <> _nil THEN osErr% = FN DISPOSHANDLE(myHandle&)
      myHandle& = _nil
    END IF
  END IF
END FN = Err%

This moves your data (or the first 255 chars of it) directly into place 
in the new handle. This is untested, so beware my typos, but it should 
start you in the right direction.

Hope that helps.
 0"0
 =J= a  y
  "

PS. On second thought, why not just dispense with the handle and move 
your data directly into the string:

LOCAL FN getVChar
  INC(gCountItems%)
  LONG IF myResultRecord.gItemType& = _TypeVChar
    theLength% = myResultRecord.gItemLength%
    IF theLength% > 253 then theLength% = 253
        Err% = FN dbGetItem% (mySessionRecord.gSessionID&, 60,
myResultRecord.gItemType&, theLength%,
myResultRecord.gItemPlaces%, myResultRecord.gItemFlag%, @theText$+2, _nil)
        LONG IF (Err% = _rcDBValue) OR (Err% = _noErr)
          POKE @theText$, theLength%+2
          POKE @theText$+1, 39
          POKE @theText$ + theLength% + 2, 39
          FN displayResults (theText$)
        XELSE
          BEEP
          theText$ = STR$(Err%)
        END IF
      END IF
    END IF
  END IF
END FN = Err%