From 8f4315465b13eb5332cd5f10b5bc9fd125d66606 Mon Sep 17 00:00:00 2001 From: skalogryz Date: Fri, 21 Nov 2014 00:12:19 +0000 Subject: [PATCH] richmemo: added FindText method to richedit helper git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3757 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/richmemo/richmemohelpers.pas | 29 ++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/components/richmemo/richmemohelpers.pas b/components/richmemo/richmemohelpers.pas index 61dbb5c04..6e56b8ad7 100644 --- a/components/richmemo/richmemohelpers.pas +++ b/components/richmemo/richmemohelpers.pas @@ -20,10 +20,10 @@ unit RichMemoHelpers; interface -uses - RichMemo, Graphics; - {$IFDEF FPC_FULLVERSION >= 20600} +uses + SysUtils, StrUtils, Graphics, + RichMemo; type TRichEditFromRichMemo = class(TObject); @@ -79,10 +79,14 @@ type { TRichEditForMemo } + TSearchType = (stWholeWord, stMatchCase); + TSearchTypes = set of TSearchType; + TRichEditForMemo = class helper for TCustomRichMemo public function SelAttributes: TTextAttributes; function Paragraph: TParaAttributes; + function FindText(const SearchStr: String; StartPos, Length: Integer; Options: TSearchTypes): Integer; end; {$ELSE} {$WARNING Class Helpers require FPC 2.6.0 or later, RichEdit compatible methods will not be available } @@ -294,6 +298,25 @@ function TRichEditForMemo.Paragraph: TParaAttributes; begin Result:=TParaAttributes(TObject(Self)); end; + +function TRichEditForMemo.FindText(const SearchStr: String; StartPos, + Length: Integer; Options: TSearchTypes): Integer; +var + sub : WideString; + src : WideString; +begin + src := UTF8Decode( TCustomRichMemo(Self).Text ); + sub := UTF8Decode(SearchStr); + if not (stMatchCase in Options) then begin + src:=WideUpperCase(src); + sub:=WideUpperCase(sub); + end; + src:=Copy(src, StartPos+1, Length); + Result:=Pos(sub, src); + if Result<=0 then Result:=-1 + else Result:=StartPos+Result-1; +end; + {$ENDIF} end.