home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / mac / programm / 15454 < prev    next >
Encoding:
Internet Message Format  |  1992-09-14  |  3.4 KB

  1. Path: sparky!uunet!stanford.edu!unix!css-mac1.sri.com!user
  2. From: mxmora@unix.sri.com (Matthew Xavier Mora)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: PathName from FSSpec (pascal code)
  5. Message-ID: <mxmora-140992131506@css-mac1.sri.com>
  6. Date: 14 Sep 92 20:13:59 GMT
  7. Sender: news@unix.SRI.COM
  8. Followup-To: comp.sys.mac.programmer
  9. Organization: SRI International
  10. Lines: 71
  11.  
  12. I spent the long weekend cursing at the AppleEventManager
  13. trying to get the finder to open a control panel. Anyway,
  14. one of the things I discovered was that the alias manager will
  15. give you a path name if you ask for it. Since my program needed to
  16. display the path name, I wrote a function that will return a full
  17. path name in a handle (not in a str255 so it won't crash with long 
  18. path names) when you give it a fsspec. 
  19.  
  20. I also figured out how to get the finder to open a control panel.
  21. You need to send an open selection event. I finally found an example that
  22. worked and ported it to pascal. If you would like to see that code I can
  23. post it here also. Its a direct copy of C.K Han's C code that is on the 
  24. developers CD.
  25.  
  26. Here is the code:
  27.  
  28. {-------------------------------------------------------------------------}
  29. {Path Name From FSSpec                                                    }
  30. {by Matthew Xavier Mora                                                   }
  31. {9-8-92                                                                   }
  32. {Given a FSSpec this function will return a handle to the full path       }
  33. {name. It creates the handle as it goes. It does not have the limited     }
  34. {string length (255) problem like the ones I have seen. This of course    }
  35. {requires system seven or better because of the use of the alias manager  }
  36. { Don't forget to dispose the handle when you are done with it.           }
  37. {-------------------------------------------------------------------------}
  38. {$PUSH}
  39. {$-R}
  40.  function PathNameFromFSSpec (var theFile: FSSpec): Handle;
  41.   var
  42.    i: AliasInfoType;
  43.    theStr: STR63;
  44.    h: Handle;
  45.    oe: OSErr;
  46.    alias: AliasHandle;
  47.    theSize: longint;
  48.  begin
  49.   PathNameFromFSSpec := nil;
  50.   oe := NewAlias(nil, theFile, alias);          {create a temporary alias}
  51.   if alias = nil then                                       {if nil exit }
  52.    exit(PathNameFromFSSpec);
  53.  
  54.   h := NewHandle(0);
  55.   if h = nil then                                          {if nil exit. }
  56.    exit(PathNameFromFSSpec);
  57.  
  58.   i := asiAliasName;                       { set the index to the Parent }
  59.   if GetAliasInfo(alias, i, thestr) = noerr then     {get The parentName }
  60.    begin                                     {returns error if bad alias }
  61.     while thestr <> '' do      { will be '' when done traversing the path}
  62.      begin
  63.       theSize := longint(thestr[0]) + 1;       
  64.       thestr[0] := ':';  { use the size byte to store the colon. aux='/' }
  65.                                                 { Let Munger do the work }
  66.       theSize := Munger(h, 0, nil, 0, @thestr, thesize); 
  67.       i := i + asiParentName;           {set the index to the next parent}
  68.       oe := GetAliasInfo(alias, i, thestr);          {get the parentName }
  69.      end;
  70.                                                     {get the Volume Name }
  71.     oe := GetAliasInfo(alias, asiVolumeName, thestr);
  72.     theSize := longint(thestr[0]);
  73.     theSize := Munger(h, 0, nil, 0, Ptr(ord(@theStr) + 1), theSize);
  74.  
  75.     PathNameFromFSSpec := h;             {return the newly created handle}
  76.    end;
  77.   DisposeHandle(Handle(alias));
  78.  end;
  79. {$POP}
  80.  
  81.  
  82. Matt
  83.