通过Delphi中的备忘录搜索?
发布时间:2020-12-15 04:22:49 所属栏目:大数据 来源:网络整理
导读:任何人都可以给我一些简单的代码,使我能够在备忘录中搜索一个简单的字符串,并在发现后在备忘录中突出显示它吗? 解决方法 此搜索允许文档换行,case(in)敏感搜索和从光标位置搜索. type TSearchOption = (soIgnoreCase,soFromStart,soWrap); TSearchOptions =
任何人都可以给我一些简单的代码,使我能够在备忘录中搜索一个简单的字符串,并在发现后在备忘录中突出显示它吗?
解决方法
此搜索允许文档换行,case(in)敏感搜索和从光标位置搜索.
type TSearchOption = (soIgnoreCase,soFromStart,soWrap); TSearchOptions = set of TSearchOption; function SearchText( Control: TCustomEdit; Search: string; SearchOptions: TSearchOptions): Boolean; var Text: string; Index: Integer; begin if soIgnoreCase in SearchOptions then begin Search := UpperCase(Search); Text := UpperCase(Control.Text); end else Text := Control.Text; Index := 0; if not (soFromStart in SearchOptions) then Index := PosEx(Search,Text,Control.SelStart + Control.SelLength + 1); if (Index = 0) and ((soFromStart in SearchOptions) or (soWrap in SearchOptions)) then Index := PosEx(Search,1); Result := Index > 0; if Result then begin Control.SelStart := Index - 1; Control.SelLength := Length(Search); end; end; 即使备注未聚焦,您也可以在备忘录上设置HideSelection = False以显示选择. 使用这样: SearchText(Memo1,Edit1.Text,[]); 也允许搜索编辑. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |