【文章內(nèi)容簡介】
@SearchString[1], Length(SearchString))。 end。 while SearchCount 0 do begin if frWholeWord in Options then if not FindNextWordStart(Result) then Break。 I := 0。 while (CharMap[Result[I]] = SearchString[I+1]) do begin Inc(I)。 if I = Length(SearchString) then begin if (not (frWholeWord in Options)) or (SearchCount = 0) or (Result[I] in WordDelimiters) then Exit。 Break。 end。 end。 Inc(Result, Direction)。 Dec(SearchCount)。 end。 Result := nil。 end。 end. 替換對話框部件 替換對話框部件為應(yīng)用程序提供替換對話框。如圖 。它包括查找對話框的所有功能,此外還允許使用者 更換被選中的字符串。 FindText 屬性是應(yīng)用程序需查找的字符串。 ReplaceText 屬性是被選中字符的替換字符串。 Options 屬性決定對話框的顯示方式。其值如表 所示。 與查找對話框一樣,替換對話框亦有 OnFind 事件。用戶輸入查找字符串并按FindNext 按鈕時,發(fā)生 OnFind 事件。用戶選擇 Replace 或 ReplacAll 時, 對話框發(fā)生 OnRelpace 事件,要替換的字符串存入 ReplaceText 屬性中,要編寫相應(yīng)的代碼以支持替換功能。 表 替換對話框的 Options 屬性的取值及含義 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 取值 含義 ──────────────────────────────────────── frRelpace 如果是真值, 應(yīng)用程序?qū)?ReplaceText 屬性中的字符串替換 FindText 屬性中的字符串。 frReplacAll 如果是真值,應(yīng)用程序?qū)?ReplaceText 屬性中的字符串替換, 查找到的所有 FindText屬性中的字符串。 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 例程中 方法響應(yīng) OnReplace 事件, Replace 方法首先判斷控制中被 選中字符串是否與替換字符串相等,如果不等則進行替換。而后根據(jù) Options中的方式循 環(huán)進行查找替換。直至無匹配字符串為止。其代碼如下: procedure (Sender: TObject)。 var Found: Boolean。 begin with ReplaceDialog1 do begin if AnsiCompareText(, FindText) = 0 then := ReplaceText。 Found := SearchMemo(Memo1, FindText, Options)。 while Found and (frReplaceAll in Options) do begin := ReplaceText。 Found := SearchMemo(Memo1, FindText, Options)。 end。 if (not Found) and (frReplace in Options) then ShowMessage(39。Cannot find 39。 + FindText + 39。.39。)。 end。 end。 打開對話框部件 打開對話框部件為應(yīng)用程序顯示打開對話框。使用 Execute 方法可顯示打開對話框用戶通過選擇文件類型下拉框中的文件類型,可以確定顯示在文件列表中的文件。 例如,如果用戶選擇 *.txt 文件類型,那么只有在當(dāng)前目錄下的文本文件才會顯示在文件列表中。文件擴展名通常也稱為過濾器。 打開對話框包含一個 Filters(過濾器 )的屬性,它可確定文件類型和在文件類型下拉框中的順序。應(yīng)用程序可以為打開對話框定義多個過濾器,對話框的FilterIndex 屬性可以決定哪個過濾器是文件類型下拉框中的缺省過濾器。如FilterIndex 等于 2,表示程序運行時出現(xiàn)在文件類型下拉框