Советы по Delphi

       

Поиск и замена текста в Tmemo


procedure TForm1.FindDialog1Find(Sender: TObject);
VAR
Buff, P, FT : PChar;BuffLen : Word;begin
WITH
Sender AS TFindDialog DOBEGINGetMem(FT, Length(FindText) + 1);StrPCopy(FT, FindText);BuffLen := Memo1.GetTextLen + 1;GetMem(Buff, BuffLen);Memo1.GetTextBuf(Buff, BuffLen);P := Buff + Memo1.SelStart + Memo1.SelLength;P := StrPos(P, FT);IF P = NIL THEN MessageBeep(0)ELSEBEGINMemo1.SelStart := P - Buff;Memo1.SelLength := Length(FindText);END;FreeMem(FT, Length(FindText) + 1);FreeMem(Buff, BuffLen);END;end;

procedure TForm1.ReplaceDialog1Replace(Sender: TObject);
begin
WITH
Sender AS TReplaceDialog DOWHILE True DOBEGINIF Memo1.SelText <> FindText THENFindDialog1Find(Sender);IF Memo1.SelLength = 0 THEN Break;Memo1.SelText := ReplaceText;IF NOT (frReplaceAll IN Options) THEN Break;END;end;
[000363]


Содержание раздела