Delphi如何让Memo选中某文字
发布网友
发布时间:2022-04-23 15:00
我来回答
共1个回答
热心网友
时间:2023-10-06 02:40
procere TForm1.FindDialog1Find(Sender: TObject);
var
FoundAt: LongInt;
StartPos, ToEnd, StartPos2: Integer;
SearchTypes : TSearchTypes;
begin
with richedit1 do
begin
if frMatchCase in FindDialog1.Options then SearchTypes := SearchTypes + [stMatchCase];
if frWholeWord in FindDialog1.Options then SearchTypes := SearchTypes + [stWholeWord];
if not(frdown in FindDialog1.Options) then
begin
StartPos := SelStart - 1;
StartPos2 := SelStart - 1;
if StartPos < 0 then
begin
messagedlg('已到达文档开头,未找到“' + FindDialog1.FindText + '”。',mtinformation,[mbok],0);
exit;
end;
while StartPos > -1 do
begin
ToEnd := Length(Text) - StartPos;
FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, SearchTypes);
if FoundAt < StartPos2 then
begin
if FoundAt > -1 then
begin
SetFocus;
SelStart := FoundAt;
SelLength := Length(FindDialog1.FindText);
if StartPos = 0 then
begin
messagedlg('已到达文档开头。',mtinformation,[mbok],0);
end;
break;
end
else
begin
StartPos := StartPos - 1;
if StartPos = -1 then
messagedlg('已到达文档开头,未找到“' + FindDialog1.FindText + '”。',mtinformation,[mbok],0);
end;
end
else
begin
StartPos := StartPos - 1;
if StartPos = -1 then
messagedlg('已到达文档开头,未找到“' + FindDialog1.FindText + '”。',mtinformation,[mbok],0);
end;
end;
end
else
begin
if Seltext = FindDialog1.FindText then
StartPos := SelStart + SelLength
else
StartPos := SelStart;
{ 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, SearchTypes);
if FoundAt <> -1 then
begin
SetFocus;
SelStart := FoundAt;
SelLength := Length(FindDialog1.FindText);
seltext := FindDialog1.FindText;
SelStart := FoundAt;
SelLength := Length(FindDialog1.FindText);
end
else
begin
messagedlg('已到达文档末尾,未找到“' + FindDialog1.FindText + '”。',mtinformation,[mbok],0);
end;
end;
end;
end;