[comp.sys.mac.programmer] Open Document AppleEvents--Sending

dwright@sif.claremont.edu (06/22/91)

Well, I haven't gotten a single reply, so let me try again.  I'm trying to send
an Open AppleEvent to another application.  The event is getting there, but the
destination application complains that it can't open the file -- so I don't
think I'm setting up the alias list correctly.

I have code this time(!):

function CreateOpenAppleEvent (theFile: FSpecPtr;
				theTarget: AEAddressDesc;
				var theAEvent: AppleEvent):  OSErr;
var
	err: osErr;
	temp: AEDesc;   resultList : AEDescList;   alias: AliasHandle;
begin

	err := NewAlias(nil, theFile^, alias);   {Create the alias}

	hlock(handle(alias));

	err := AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments,
			theTarget, kAutoGenerateReturnID,
				kAnyTransactionID, theAEvent);

	err := AECreateList(nil, 0, false, resultList);

	err := AECreateDesc(typeAlias, ptr(Alias^), sizeof(AliasRecord),
				temp);

	err := AEPutDesc(resultList, 1, temp);

	err := AEPutParamDesc(theAEvent, keyDirectObject, resultList);

	CreateOpenEvent := err;
end; {CreateOpenAppleEvent}

:
:
err := CreateOpenAppleEvent(document, theTarget, theEvent);
if err = noErr then
		err := AESend (theEvent, theReply, kAENoReply,
			kAENormalPriority, kNoTimeOut, nil, nil);


----------
I've abbreviated the code a little (mainly the error-handling code) to keep it
concise.  NONE of the calls is returning an error.
Any clues as to what I'm doing wrong??
>>Please reply by e-mail.  Our news machine seems to go down without warning
for weeks at a time without warning during the summer...:-)/:-(

Thanks!
Dan Wright
(dwright@sif.claremont.edu  or, if that fails, wwright@hobbes.kzoo.edu)
------------------------------------------------------------------------
Dan Wright                              dwright@sif.claremont.edu
Harvey Mudd College '92, Claremont, CA

lai@Apple.COM (Ed Lai) (06/24/91)

The problem is in

err := AECreateDesc(typeAlias, ptr(Alias^), sizeof(AliasRecord), temp);

AliasRecord is just the header, so the content part of the Alias is missing.

It should be

err := AECreateDesc(typeAlias, ptr(Alias^), GetHandleSize(Handle(Alias), temp);


The code now is correct, and it can be more compact.

function CreateOpenAppleEvent (theFile: FSpecPtr;
                                theTarget: AEAddressDesc;
                                var theAEvent: AppleEvent):  OSErr;
var
erateReturnID,
												kAnyTransactionID, theAEvent);

 err := AEPutParamDesc(theAEvent, keyDirectObject, temp);

 err := AEDisposeDesc(temp);

 CreateOpenEvent := err;
end; {CreateOpenAppleEvent}

Again error handling has been omitted.

The create list has been omitted because there is only 1 item on the list.



/* Disclaimer: All statments and opinions expressed are my own */
/* Edmund K. Lai                                               */
/* Apple Computer, MS37-UP                                     */
/* 20525 Mariani Ave,                                          */
/* Cupertino, CA 95014                                         */
/* (408)974-6272                                               */
zW@h9cOi

lai@Apple.COM (Ed Lai) (06/29/91)

In article <54275@apple.Apple.COM> lai@Apple.COM (Ed Lai) writes:
>
> err := AEPutParamDesc(theAEvent, keyDirectObject, temp);
>
> err := AEDisposeDesc(temp);
>
> CreateOpenEvent := err;
>end; {CreateOpenAppleEvent}
>
>Again error handling has been omitted.
>
>The create list has been omitted because there is only 1 item on the list.
>

It turns out the above simplification would not work if you are sending the
event to TeachText or non-AppleEvent aware application. In that case you
still have to create the list and put the alias into the list first.

/* Disclaimer: All statments and opinions expressed are my own */
/* Edmund K. Lai                                               */
/* Apple Computer, MS37-UP                                     */
/* 20525 Mariani Ave,                                          */
/* Cupertino, CA 95014                                         */
/* (408)974-6272                                               */
zW@h9cOi