[comp.sys.mac.programmer] ?'s about HC 2.0 XCMD Text Edit stuff

Edward.Blakes.Jr.@f13.n396.z1.mmug.edgar.mn.org (Edward Blakes Jr.) (03/01/91)

I'm trying to be able to "cut and paste" lines between fields in HC 2.0.
I'm writing an XCMD to do it.  Whenever I try to call TECopy(), 
GetStylHandle(), or really anything that fools with the TE scrap, HC goes
kablooey (sp?) and "unexpectedly quits (1)".  Below is an excerpt of the 
code.  I'm using Think C 4.0.2.  Am I doing something wrong?  Am I not 
allowed to put something in the scrap areas in Hypercard or perhaps as a
code resource?  I wish I could phrase better questions but I don't know 
what to ask.  Also, does GetFieldTE() return a copy of the TE record or a
copy of the handle to the field's TE record?  Any input would be appreciated.

Ed Blakes
blakes@rex.cs.tulane.edu

******** Here's the code **********************************
	/* other declarations, etc. */
	
	TEHandle	fieldTE, toTE;		/* TE record of field */
	Handle		htxt;			/* Handle to text */
	StScrpHandle txt_scrap;		/* Handle to text style scrap */
	TEHandle	tempTE;			/* TE handle to temp area for pasting */

	/* Get params stuff.  Nothing fishy here */
	
	
	/* Get fieldTE of FROM field and TO field */

	fieldTE = GetFieldTE(paramPtr, TRUE, fromID, 0, NIL);
	toTE = GetFieldTE(paramPtr,TRUE,toID,0,NIL);

	/* Select the entire toTE and paste it to a temp TErec */
	TESetSelect(0,32767,toTE);

	/*** HC dies right here ***/
	TECopy (toTE);
	TEStylPaste(tempTE);
	
	TESetSelect(1,20,fieldTE);
	htxt = TEGetText(fieldTE);
	txt_scrap = GetStylScrap(fieldTE);
	TESetSelect(0,0,tempTE);
	HLock(htxt);
	TEStylInsert(*htxt,19,txt_scrap,tempTE);
	HUnlock(htxt);
	SetFieldTE(paramPtr,TRUE,toID,0,NIL,tempTE);
	
	/* Dispose of TEHandle */
	etc.
	---

--  
Edward Blakes Jr. - via The Minnesota Macintosh Users Group UUCP-Fido Gateway
UUCP: ...jhereg!kksys!vware!edgar!mmug!396!13!Edward.Blakes.Jr.
INET: Edward.Blakes.Jr.@f13.n396.z1.mmug.edgar.mn.org

Roger.W.Brown@dartmouth.edu (Roger W. Brown) (03/19/91)

In article <4.27CF2777@mmug.edgar.mn.org>
Edward.Blakes.Jr.@f13.n396.z1.mmug.edgar.mn.org (Edward Blakes Jr.)
writes:

> ******** Here's the code **********************************
> 	/* other declarations, etc. */
> 	
> 	TEHandle	fieldTE, toTE;		/* TE record of field */
> 	Handle		htxt;			/* Handle to text */
> 	StScrpHandle txt_scrap;		/* Handle to text style scrap */
> 	TEHandle	tempTE;			/* TE handle to temp area for pasting */
> 
> 	/* Get params stuff.  Nothing fishy here */
> 	
> 	
> 	/* Get fieldTE of FROM field and TO field */
> 
> 	fieldTE = GetFieldTE(paramPtr, TRUE, fromID, 0, NIL);
> 	toTE = GetFieldTE(paramPtr,TRUE,toID,0,NIL);
> 
> 	/* Select the entire toTE and paste it to a temp TErec */
> 	TESetSelect(0,32767,toTE);
> 
> 	/*** HC dies right here ***/
> 	TECopy (toTE);
> 	TEStylPaste(tempTE);
> 	


1. From the "final Version" fo the extended XCMD interface docs from
Apple: "the XCMD should NOT use the TEHandle returned by this callback
before adjusting the TEHandle^^.inPort field to point to another
grafport." .. because you might draw into the card's port. Maybe you
might also bomb??

2. Have you allocated tempTE somewhere?

>  Also, does GetFieldTE() return a copy of the TE record or a
copy of the handle to the field's TE record?

A copy of the whole record; you are instructed to dispose of the handle
when you are done. If it was not a handle, the real data would be
disposed along with it.

Any help? 
-----------------------------------------------------------------
Roger Brown                           Roger.W.Brown@dartmouth.edu
Courseware Development
Dartmouth College, Hanover, NH