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

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

From: tedd <tedd@...>
Date: Sat, 11 Sep 1999 12:31:57 -0400
=J= a  y

I modified your code a little to do more specifically what I wanted --
which was to create two functions that: 1) If given a string, would return
a handle; 2) if given a handle, would return a string.

You might want to review the following code to see if I blundered.

Thanks again for the primer.

tedd

'--- will run as is --

COMPILE  0,_dimmedVarsOnly
END GLOBALS

'--------------------------

LOCAL FN buildWind
  WINDOW 1,"String <=> Handle",(0,0)-(300,100),_docNoGrow
END FN

'--------------------------

LOCAL FN str2Hndl(@theStr&)
  DIM size
  DIM err
  DIM theHndl&

  theHndl& = FN NEWHANDLE(0)
  LONG IF theHndl&
    size = PEEK(theStr&)
    err = FN SETHANDLESIZE(theHndl&,size)
    BLOCKMOVE theStr&+1,[theHndl&],size
  XELSE
    theHndl& = _nil
  END IF

END FN = theHndl&

'--------------------------

LOCAL FN hndl2Str$(theHndl&)
  DIM size
  DIM theStr$
  DIM theStr&

  LONG IF theHndl&
    theStr& = @theStr$
    size = FN GETHANDLESIZE(theHndl&)
    IF size > 255 THEN size = 255
    POKE theStr&, size
    BLOCKMOVE [theHndl&],theStr&+1,size
  XELSE
    theStr$ = ""
  END IF

END FN = theStr$

'--------------------------

"MAIN"

FN buildWind
DIM myStr$
DIM myNewStr$
DIM myHndl&

myStr$ = "  It works. Click to end."

myHndl&   = FN str2Hndl(myStr$)
myNewStr$ = FN hndl2Str$(myHndl&)

PRINT myNewStr$

DO
UNTIL FN BUTTON

DEF DISPOSEH(myHndl&)

___________________________________________________________________
<mailto:tedd@...>	               http://sperling.com/