Beranda > Delphi > RichEdit Search and Replace

RichEdit Search and Replace

The following will Search for a String and replace it with Replacement String in RichEdit

procedure TForm1.RearchAndReplace(InSearch,
InReplace: string);
var X, ToEnd   : integer;
Save_Cursor : TCursor;
begin
Save_Cursor := Screen.Cursor;
Screen.Cursor := crHourglass;
with RichEdit1 do
begin
X := 0;
ToEnd := length(Text);
X := FindText(inSearch, X, ToEnd, []);
while X <> -1 do
begin
SetFocus;
SelStart := X;
SelLength := length(inSearch);
SelText := InReplace;
X := FindText(inSearch, X + length(InReplace),
ToEnd, []);
end;
end;
Screen.Cursor := Save_Cursor;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
SearchText, ReplaceText: string;
begin
SearchText := 'large';
ReplaceText := 'small';
RearchAndReplace(SearchText, ReplaceText);
end;

Iklan
Kategori:Delphi
  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: