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
This commit is contained in:
skalogryz
2014-11-21 00:12:19 +00:00
parent 7b7b13b4c6
commit 8f4315465b

View File

@ -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.