[futurebasic] Re: HANDANDHAND failure

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

From: Jay Reeve <jktr@...>
Date: Sat, 28 Mar 98 00:55:03 -0000
>I try to join two pieces of data pointed by handles with a separator in
>between,...
>FN HANDANDHAND seems to work ok if it is called only once.

Alain,

I don't know for sure, but I suspect your difficulty may be in trying to 
combine _locked_ handles. In order to do its thing, the memory manager 
needs to be able to move handles around when combining them with FN 
HANDANDHAND. If you lock them, it can mess things up.

While locking handles to use them is _usually_ not a bad idea, the whole 
point of handles is that they _can_ move around when needed, and this may 
be one of those times.

Also, for adding your separator, I would just enlarge the first 
(unlocked) handle rather than bothering with a new one, like this:

CLEAR LOCAL FN accrocherub(r1,r2)
  DIM 3 sep$
  DIM OSErr
  DIM HandleRub1&,HandleRub2&
  DIM size
  	LONG IF r1>0 AND r2>0                  'just in case of invalid params
    HandleRub1& = glafiche.RubHndl&(r1)   'get first locked data handle
    HandleRub2& = glafiche.RubHndl&(r2)   'get second locked data handle
'If these are in fact locked, now would be a good time to unlock them!

    'test first param and if there is something to add
    LONG IF r1=1 AND FN GETHANDLESIZE(HandleRub2&)>1
      size = FN GETHANDLESIZE(HandleRub1&)
      sep$=" - "                          'separator string
      OSErr = FN SETHANDLESIZE(HandleRub1&,size+3)
      BLOCKMOVE @sep$+1,[strHndl&]+size,3 'add sep to first handle

      'VVV What does this do? Just curious.
      DATA handle
    END IF

  END IF
  'now try to add the second data handle to the first one
  OSErr= FN HANDANDHAND(HandleRub2&,HandleRub1&)
'If you really need the handles locked, they can be relocked here.
END FN

Hope that's a help.
 @^@
 =J= a  y