Delphi 编写记事本 两个组件帮忙解决下!
1.FindDialog //查找组件
2.ReplaceDinalog//查找替换组件
delphi编写记事本的时候有两个组件我不会使用它,
谁帮帮下?
1.FindDialog //查找组件
2.ReplaceDinalog//查找替换组件
delphi编写记事本的时候有两个组件我不会使用它,
谁帮帮下?
答案:procedure TForm1.Button1Click(Sender: TObject);
begin
FindDialog1.Position := Point(RichEdit1.Left + RichEdit1.Width, RichEdit1.Top);
FindDialog1.Execute;
end;
procedure TForm1.FindDialog1Find(Sender: TObject);
var
FoundAt: LongInt;
StartPos, ToEnd: Integer;
begin
with RichEdit1 do
begin
{ begin the search after the current selection if there is one }
{ otherwise, begin at the start of the text }
if SelLength <> 0 then
StartPos := SelStart + SelLength
else
StartPos := 0;
{ ToEnd is the length from StartPos to the end of the text in the rich edit control }
ToEnd := Length(Text) - StartPos;
FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, [stMatchCase]);
if FoundAt <> -1 then
begin
SetFocus;
SelStart := FoundAt;
SelLength := Length(FindDialog1.FindText);
end;
end;
end;
procedure TForm1.ReplaceDialog1Replace(Sender: TObject);
var
SelPos: Integer;
begin
with TReplaceDialog(Sender) do
begin
{ Perform a global case-sensitive search for FindText in Memo1 }
SelPos := Pos(FindText, Memo1.Lines.Text);
if SelPos > 0 then
begin
Memo1.SelStart := SelPos - 1;
Memo1.SelLength := Length(FindText);
{ Replace selected text with ReplaceText }
Memo1.SelText := ReplaceText;
end
else MessageDlg(Concat('Could not find "', FindText, '" in Memo1.'), mtError, [mbOk], 0);
end;
end;