Problem z Memo

0

Dałem Memo (o nazwie nota) i finddialog1. Jako procedure wyszkukiwania:

nota.SelStart := Pos(finddialog1.FindText, nota.text)-1;
nota.SelEnd := nota.SelEnd+length(finddialog1.FindText)-1;

Wszytsko działa, ale tylko raz. Procedura ta wyszukuje tylko pierpszą szukaną frazę, a jak przerobić ją żeby szukała wszystkie?? (FindText nie działa w komponencie memo )

0

Jeżeli macie D7 to użyjcie PosEx. Jeżeli nie to musicie skopiować...
A zresztą. Podawałem kiedyś tutaj kod jak to zrobić. Poszukajcie.

0

Zastąp Memo RichEditem - to żaden problem...

0

W helpie jest przykłąd dla MEMO!!
eee po co ja na to odpowiadam, przecież to jest przeterminowane.

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

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);
while Found and (frReplaceAll in Options) do
begin
EditControl.SelText := ReplaceText;
Found := SearchEdit(EditControl, FindText, Options);
end;
if (not Found) and (frReplace in Options) then
ShowMessage(Format('Tekst "%s" nie został znaleziony', [FindText]));
end;

end.

Wywołanie: SearchEdit(nota, 'String którego szukasz', FindDialog1.Options);
Z replace podobnie

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