[futurebasic] Re: [FB] String <=> Handle

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 1999 : Group Archive : Group : All Groups

From: "Michael Evans" <mikonic@...>
Date: Fri, 10 Sep 1999 23:02:47 -0400
>>Hi gang:
>>
>>Does anyone have a cool way of going from a string$ to a handle& -- and
>>back again? Something like: Given a string, how does one make a handle for
>>it? And, given a handle, how does one create a string of its contents?
>>
>>I know that I can find the length of a string; create a block of memory the
>>same size; and then POKE the string's values into memory. I also aware that
>>if I know the handle of a block of memory then I can PEEK the contents of
>>the block into a string. But, I'm looking for something a bit
>>shorter/cooler to do those things -- if there is such a critter.
>>
>>Many thanks in advance for any replies.
>>
>>tedd

try this:

CLEAR LOCAL
LOCAL FN testStringToHandleToString
  DIM myString$, myOtherString$
  DIM myStrSize%, myStrSize&
  DIM myStrHandle&, err%

  myString$    = "This be a test!"

  myStrSize%   = LEN(myString$)

  myStrSize&   = myStrSize%    'BLOCKMOVE and FN NEWHANDLE require a long&

  myStrHandle& = FN NEWHANDLE(myStrSize&)

  LONG IF myStrHandle&
    err% = FN HLOCK(myStrHandle&)

    BLOCKMOVE (@myString$ + 1), [myStrHandle&], myStrSize&

    myStrSize& = FN GETHANDLESIZE(myStrHandle&)
    myStrSize% = myStrSize&

    POKE @myOtherString$, myStrSize%
    BLOCKMOVE [myStrHandle&], (@myOtherString$ + 1), myStrSize&

    err% = FN HUNLOCK(myStrHandle&)

    DEF DISPOSEH(myStrHandle&)
  END IF

  PRINT myString$
  PRINT myOtherString$

END FN




----------------------------------------------------------
Michael Evans
Manager of Software Development * Photo Systems, Inc.
3301 Wood Valley Road, NW * Atlanta, GA, 30327-1515
Voice: (404) 846-9386
Fax: (404) 240-0878 * Cell: (404) 229-3930
E-mail: evans@... * michael_evans@...
----------------------------------------------------------