home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Pascal / source / path-from-fsspec-pas.txt < prev    next >
Encoding:
Internet Message Format  |  1994-03-23  |  3.2 KB  |  [TEXT/EDIT]

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