FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

MEMORY

Know if an address is related to a pointer or a handle


'*******************************
' Testing for handles & pointers
'*******************************
GLOBALS
DIM txt$
DIM handle&
END GLOBALS
'==============
LOCAL FN IsThatAHandle(memaddress&)
END FN=(FN HGETSTATE(memaddress&)>-1)
'==============
CLEAR LOCAL
  DIM i
LOCAL FN printresult(isHandle,memaddress&)
  SELECT isHandle
    CASE _false
      PRINT "This is a pointer the data are : ";:PRINT
      PSTR$(memaddress&)
    CASE _Ztrue
      PRINT "This is a handle the data are : ";
      LONG IF FN HLOCK(memaddress&)=_noerr
        FOR i=0 TO FN GETHANDLESIZE(memaddress&)-1
          PRINT CHR$(PEEK([memaddress&]+i));
        NEXT
      PRINT
      i=FN HUNLOCK(memaddress&)
    END IF
  END SELECT
END FN
'==============
CLEAR LOCAL
  DIM OSErr
LOCAL FN CopyStr2Handle(txtad&,hndlad&)
  LONG IF FN HLOCK(hndlad&)=_noerr
    BLOCKMOVE txtad&+1,[hndlad&],PEEK(txtad&)
    OSErr=FN HUNLOCK(hndlad&)
  END IF
END FN
'==============
LOCAL FN TestHndNPtr(firstadr&,secondadr&)
  FN printresult(FN IsThatAHandle(firstadr&),firstadr&)
  FN printresult(FN IsThatAHandle(secondadr&),secondadr&)
END FN
'==============
"MAIN"
WINDOW 1
txt$="This is a test"
handle&=FN NEWHANDLE(PEEK(@txt$))
LONG IF handle&
  FN CopyStr2Handle(@txt$,handle&)
  PRINT "param 1 is a pointer, param 2 is a handle"
  FN TestHndNPtr(@txt$,handle&)
  PRINT:PRINT "now swaping params : param 1 is a handle, param 2 a pointer"
  FN TestHndNPtr(handle&,@txt$)
  DEF DISPOSEH(handle&)
END IF
DO
UNTIL FN BUTTON
END
'*******************************

Alain