jak wyszukiwać w TMemo

0

Chcę wyszukiwać w Memo tylko nie wiem jak to zrobić.
sam łańcuch znajduję poleceniem pos. Niestety nie przesuwa siękursor na tą pozycję (linię).
Zupełnie nie wiem jak to zrobić, żeby szukany tekst przesunął się i był podświetlony (zaznaczony).
Dziękuję za pomoc.
[cya]

0

w faq masz jak zrobic to w richedit to przerób troche ten kod na swoje memo

0
unit SearchUnit;

interface

uses StdCtrls, Dialogs, StrUtils, SysUtils;

function SearchEdit(EditControl: TCustomEdit; const SearchString: String;
  Options: TFindOptions; FindFirst: Boolean = False): Boolean;

procedure ReplaceEdit(EditControl: TCustomEdit; Const FindText,ReplaceText:string;Options: TFindOptions);

implementation

{ SearchEdit scans the text of a TCustomEdit-derived component for a given
  search string.  The search starts at the current caret position in the
  control unless FindFirst is true then the search starts at the beginning.
  The Options parameter determines whether the search runs forward
  (frDown) or backward from the caret position, whether or not the text
  comparison is case sensitive, and whether the matching string must be a
  whole word.  If text is already selected in the control, the search starts
  at the 'far end' of the selection (SelStart if searching backwards, SelEnd
  if searching forwards).  If a match is found, the control's text selection
  is changed to select the found text and the function returns True.  If no
  match is found, the function returns False. }

function SearchEdit(EditControl: TCustomEdit; const SearchString: String;
  Options: TFindOptions; FindFirst: Boolean = False): Boolean;
var
  Buffer, P: PChar;
  Size: Word;
  SearchOptions: TStringSearchOptions;
begin
  Result := False;
  if (Length(SearchString) = 0) then Exit;
  Size := EditControl.GetTextLen;
  if (Size = 0) then Exit;
  Buffer := StrAlloc(Size + 1);
  try
    SearchOptions := [];
    if frDown in Options then
      Include(SearchOptions, soDown);
    if frMatchCase in Options then
      Include(SearchOptions, soMatchCase);
    if frWholeWord in Options then
      Include(SearchOptions, soWholeWord);
    EditControl.GetTextBuf(Buffer, Size + 1);
    if FindFirst then
      P := SearchBuf(Buffer, Size, 0, EditControl.SelLength,
             SearchString, SearchOptions)
    else
      P := SearchBuf(Buffer, Size, EditControl.SelStart, EditControl.SelLength,
             SearchString, SearchOptions);
    if P <> nil then
    begin
      EditControl.SelStart := P - Buffer;
      EditControl.SelLength := Length(SearchString);
      Result := True;
    end;
  finally
    StrDispose(Buffer);
  end;
end;

procedure ReplaceEdit(EditControl: TCustomEdit; Const FindText,ReplaceText:string;Options: TFindOptions);
var
  Found: Boolean;
begin
  if AnsiCompareText(EditControl.SelText, FindText) = 0 then
    EditControl.SelText := ReplaceText;
  Found := SearchEdit(EditControl, FindText, Options);
  if frReplaceAll in Options then
    begin
      EditControl.SelectAll;
      EditControl.SelText:=StringReplace(EditControl.SelText, FindText,
        ReplaceText, [rfReplaceAll]);
    end;
  if (not Found) and (frReplace in Options) then
    ShowMessage(Format('Tekst "%s" nie został znaleziony', [FindText]));
end;

end.

1 użytkowników online, w tym zalogowanych: 0, gości: 1