FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

DISK I/O

Read the comments of a file


I had this same question a couple of years ago. Rick Brown was kind enough to put this demo together. Thanks again Rick. This has been very helpful to me.

Joe:
In response to your message to the FutureBASIC mailing list, here's a short demo illustrating the use of those PBDT* functions.

'=======================
' This is a simple demo which illustrates the
' use of routines which read & set Finder comments.
' Because this demo uses a simple "File Open" dialog
' to let the user select the file, it won't currently
' handle comments for alias files, folders nor volumes.
'=======================
COMPILE 0, _caseInsensitive
'========= constants =======
_ioDTRefNum = 24
_ioDTBuffer = 32
_ioDTReqCount = 36
_ioDTActCount = 40
'========= globals ======
DIM gAction
END GLOBALS
'========= functions =======
LOCAL FN PBDTGetPath(pBlkPtr&)
  ` move.l ^pBlkPtr&,a0 ;pblock
  ` moveq #$20,d0 ;selector
  ` dc.w $a260 ;HFSdispatch
  ` ext.l d0 ;result comes back in DO.w
END FN
'---------------------------------
LOCAL FN PBDTGetCommentSync(pBlkPtr&)
  ` move.l ^pBlkPtr&,a0 ;pblock
  ` moveq #$2a,d0 ;selector
  ` dc.w $a260 ;HFSdispatch
  ` ext.l d0 ;result comes back in DO.w
END FN
'---------------------------------
LOCAL FN PBDTSetCommentSync(pBlkPtr&)
  ` move.l ^pBlkPtr&,a0 ;pblock
  ` moveq #$28,d0 ;selector
  ` dc.w $a260 ;HFSdispatch
  ` ext.l d0 ;result comes back in DO.w
END FN
'---------------------------------
LOCAL FN PBDTFlush(pBlkPtr&, async)
  LONG IF async
    ` move.l ^pBlkPtr&,a0
    ` moveq #$2b,d0
    ` dc.w $a660 ;async version of HFSdispatch
    ` move.w d0,^OSErr
  XELSE
    ` move.l ^pBlkPtr&,a0
    ` moveq #$2b,d0
    ` dc.w $a260
    ` move.w d0,^OSErr
  END IF
END FN = OSErr
'---------------------------------
LOCAL FN DoDialog
  evnt = DIALOG(0)
  id = DIALOG(evnt)
  SELECT CASE evnt
    CASE _btnClick
      SELECT CASE id
        CASE 1: gAction = 1 '(set comment)
        CASE 2: gAction = 2 '(cancel)
      END SELECT
  END SELECT
END FN
'========= main =======
DIM dtpb.104, commentBuffer.200, wdpb.52
WINDOW OFF
WINDOW 1, "Comment Demo", (0,0)-(250,150), _docNoGrow+_noGoAway
TEXT _monaco, 9
EDIT FIELD 1, "", (10,30)-(240,120), _framed
TEXT _geneva, 12
BUTTON 1, _enable, "Set Comments", (140,130)-(240,146)
BUTTON 2, _enable, "Cancel", (10,130)-(100,146)
ON DIALOG FN DoDialog
DO
  filename$ = FILES$(_fOpen, "",, vRefNum)
  LONG IF filename$ <> ""
    OSErr = 0
    CLS
    dtpb.ioCompletion& = _nil
    dtpb.ioNamePtr& = _nil
    dtpb.ioVRefNum% = vRefNum
    OSErr = FN PBDTGetPath(@dtpb) '(to fill in the ioDTRefNum field)
    LONG IF OSErr = _noErr
      dtpb.ioNamePtr& = @filename$
      dtpb.ioDTBuffer& = @commentBuffer
'Get the DirID corresponding to vRefNum:
      wdpb.ioCompletion& = _nil
      wdpb.ioNamePtr& = _nil
      wdpb.ioVRefNum% = vRefNum
      wdpb.ioWDIndex% = 0
      wdpb.ioWDProcID& = _nil
      wdpb.ioWDVRefNum% = 0 '(I.M. fails to explain why this is input!)
      OSErr = FN GETWDINFO(@wdpb)
      LONG IF OSErr = _noErr
        dtpb.ioDirID& = wdpb.ioWDDirID&
        dtpb.ioDTReqCount& = 200 ' Rick's fix
        OSErr = FN PBDTGetCommentSync(@dtpb)
        SELECT CASE OSErr
          CASE _noErr
            charCount = dtpb.ioDTActCount&
            POKE @theComment$, charCount
            BLOCKMOVE @commentBuffer, @theComment$+1, charCount
            EDIT$(1) = theComment$
          CASE _afpItemNotFound
            EDIT$(1) = "" '(no comment)
            OSErr = _noErr
          CASE ELSE
            BEEP: PRINT "PBDTGetCommentSync OSErr: "; OSErr
        END SELECT
      XELSE
        BEEP: PRINT "GetWDInfo OSErr: "; OSErr
      END IF
    XELSE
      BEEP: PRINT "PBDTGetPath OSErr: "; OSErr
    END IF
    gAction = 0
    DO
      HANDLEEVENTS
    UNTIL gAction <> 0
    LONG IF gAction = 1 AND OSErr = _noErr
'Set Comments:
      theComment$ = LEFT$(EDIT$(1),200)
      IF LEN(theComment$) > 0 THEN BLOCKMOVE @theComment$+1, @commentBuffer, LEN(theComment$)
      dtpb.ioDTReqCount& = LEN(theComment$)
'(all the other required fields in dtpb are already filled in
'from above calls to PBDTGetPath and PBDTGetCommentSync. In
'general, the following fields must be filled in, before calling
'PBDTSetCommentSync: ioCompletion&, ioNamePtr&, ioDTRefNum%,
'ioDTBuffer&, ioDTReqCount&, and ioDirID&.)
      OSErr = FN PBDTSetCommentSync(@dtpb)
      LONG IF OSErr = _noErr
        OSErr = FN PBDTFlush(@dtpb, _false)
        LONG IF OSErr
          BEEP: PRINT "PBDTFlush OSErr: "; OSErr
          DELAY 3000
        END IF
      XELSE
        BEEP: PRINT "PBDTSetComment OSErr: "; OSErr
        DELAY 3000
      END IF
    END IF
  END IF
UNTIL filename$ = ""

I re-visited this demo since Forrest posted his request, and I found that it doesn't quite work as written on my new (G3, OS 8.0) Mac. (Specifically, it seems to _set_ comments ok but doesn't _get_ them). Iplayed around with it and found that if I set dtpb.ioDTReqCount& to 200 before calling FN PBDTGetCommentSync, then it seems to work ok again. Inside Mac does not mention this as a required input parameter. Maybe this is something new with OS 8.x? At any rate, the version of the demo that I just uploaded to the FB webring has this fix in it.

Rick