【正文】
)。 if Source 0 then raise (FmtLoadStr(SFOpenError, [FileName]))。 if Dest 0 then raise (FmtLoadStr(SFCreateError,[Destination]))。 if BytesCopied 0 then FileWrite(Dest, CopyBuffer^, BytesCopied)。 finally FileSetDate(Dest,TimeStamp)。 end。 end。 end。 如果我們不使用 FileSetDate 過程, Windows 自動(dòng)把當(dāng)前時(shí)間作為時(shí)間戳寫入文件。 fmxutils 單元中的MoveFile 過程實(shí)現(xiàn)了這一功能。 var Destination: TFileName。 if not RenameFile(FileName, Destination) then begin if HasAttr(FileName, faReadOnly) then raise (Format(SFCantMove, [FileName]))。 DeleteFile(FileName)。 end。 有關(guān)自定義異常類請參閱第十二章。它們都以文件名為參數(shù)。 一致的界面 文件拷貝、文件移動(dòng)、 文件更名以及后邊的改變當(dāng)前目錄在形式上都表現(xiàn)為從一個(gè)源文件到一個(gè)目標(biāo)文件。當(dāng)用戶按 OK 鍵關(guān)閉且目標(biāo)文件 (目錄 )非空時(shí),程序彈出一個(gè)消息對話框要求用戶進(jìn)一步確認(rèn),而后執(zhí)行相應(yīng)的動(dòng)作。 var ChangeForm: TChangeForm。 begin ChangeForm := (Self)。 with ChangeForm do begin if Sender = Move1 then Caption := 39。 else if Sender = Copy1 then Caption := 39。 else if Sender = Rename1 then Caption := 39。 else if Sender = ChangeDirectory1 then begin Caption:=39。 IsFile:=False。 if IsFile then begin := 。 := 39。 end else begin := []。 := 39。 end。39。 end。 其中用到的自定義私有過程 ConfirmChange 用于執(zhí)行相應(yīng)的動(dòng)作: procedure (const ACaption, FromFile, ToFile: String)。%s %s to %s39。Move39。Copy39。Rename39。Change Directory39。 。 end。 Properties 菜單項(xiàng)的 Click 事件處理過程如下: procedure (Sender: TObject)。 FileAttrForm: TFileAttrForm。 ShowFileAttr(FileAttrForm,)。 其中過程 ShowFileAttr 的實(shí)現(xiàn)如下: procedure (FileAttrForm:TFileAttrForm。 var Attributes,NewAttributes: Word。 := Directory。 Attributes := FileGetAttr(AFileName)。 := (Attributes and faArchive) = faArchive。 := (Attributes and faHidden) = faHidden。 if then NewAttributes := NewAttributes or faReadOnly else NewAttributes := NewAttributes and not faReadOnly。 if then NewAttributes := NewAttributes or faSysFile else NewAttributes := NewAttributes and not faSysFile。 if NewAttributes Attributes then FileSetAttr(AFileName, NewAttributes)。 end。 以上過程中用到的函數(shù) FileDataTime 在 fmxutils 單元中定義,返回一個(gè)TDatatime 類型的變量。 begin Result := FileDateToDateTime(FileAge(FileName))。 其它文件管理功能的實(shí)現(xiàn) 在子窗口的 Function 菜單中,定義了一些其它的文件管理功能: ● Search :查找一個(gè)給定名字的文件,若存在則顯示該文件屬性 ● Disk View :顯示當(dāng)前驅(qū)動(dòng)器的大小和剩余空間 ● View type :確定顯示文件的類型 文件查找 當(dāng)用戶單擊 Search 菜單項(xiàng)時(shí),程序彈出一個(gè)對話框 (如圖 ),要求輸入待查找的文件名和查找路徑。當(dāng)用戶確認(rèn)后程序顯示第一個(gè)匹配文件的屬性 (如圖 )。 在實(shí)現(xiàn)這一功能的最初設(shè)計(jì)中,我試圖使用 FileSearch 函數(shù),這個(gè)函數(shù)允許在多個(gè)不同路徑中查找。 沒有辦法我只能再次使用 FindFirst,這個(gè)函數(shù)的特性在 節(jié)中已進(jìn)行了介紹。 procedure (Sender: TObject)。 FileAttrForm: TFileAttrForm。 SearchRec: TSearchRec。 begin SearchForm := (self)。39。 if (ShowModal idCancel) and ( 39。) and ( 39。) then begin FindIt := +39。+。 if Return 0 then FindIt := 39。 else FindIt := ExpandFileName()。 if FindIt = 39。 then MessageDlg(39。, mtWarning, [mbOk], 0) else begin Path := ExtractFilePath(FindIt)。 FileAttrForm := (self)。 end。 end。 procedure (Sender: TObject)。 Free,Total: LongInt。 Total := DiskSize(0)。 bytes.39。 bytes.39。 DiskFree、 DiskSize 帶參數(shù)為 0