Help please: macoslib DocumentFile(extends w as Window, assigns f as FolderItem)

Hello,
I am having a problem when f is nil in “DocumentFile(extends w as Window, assigns f as FolderItem)” the code for it seems to have been omitted…

DocumentFile(extends w as Window, assigns f as FolderItem)

if w.Handle = 0 then
return
end if

#if targetCarbon
if f is nil then
declare function RemoveWindowProxy lib CarbonLib (inWindow as WindowPtr) as Integer

  dim OSError as Integer = RemoveWindowProxy(w)
else
  declare function FSNewAlias lib CarbonLib (fromFile as Ptr, fsRef as Ptr, ByRef inAlias as Ptr) as Short
  
  dim aliasHandle as Ptr
  dim fileRef as FSRef = FileManager.GetFSRefFromFolderItem(f)
  dim OSError as Integer = FSNewAlias(nil, fileRef, aliasHandle)
  if OSError <> 0 then
    return
  end if
  
  declare function SetWindowProxyAlias lib CarbonLib (inWindow as WindowPtr, inAlias as Ptr) as Integer
  
  OSError = SetWindowProxyAlias(w, aliasHandle)
  if aliasHandle <> nil then
    soft declare sub DisposeHandle lib CarbonLib (h as Ptr)
    DisposeHandle aliasHandle
    aliasHandle = nil
  end if
end if

#endif

#if targetCocoa
declare sub setTitleWithRepresentedFilename lib CocoaLib selector “setTitleWithRepresentedFilename:” (id as Ptr, filePath as CFStringRef)

setTitleWithRepresentedFilename Ptr(w.Handle), f.POSIXPath

#endif

How can I fix it?

Thanks.

Lennox

The problem is in the Cocoa part #if targetCocoa
How can I fix it?

Thanks.

Lennox

It just needs to check for nil and pass an empty path.

dim fPath as string if f<>nil then fPath=f.POSIXPath setTitleWithRepresentedFilename Ptr(w.Handle), fPath

Thanks Jim,

This was my workaround…
if f is nil then
else
declare sub setTitleWithRepresentedFilename lib CocoaLib selector “setTitleWithRepresentedFilename:” (id as Ptr, filePath as CFStringRef)
setTitleWithRepresentedFilename Ptr(w.Handle), f.POSIXPath
end if

Both work, but I do not know which is better.

Thanks.

Lennox

If you skip the call to setTitleWithRepresentedFilename then if the window already has a file icon, it will keep it.

If the file is nil, you likely want to clear the file icon from the window. Passing an empty path clears the icon.

Thanks Jim,
I see.
Lennox