Delphi如何让Memo选中某文字
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
1个回答
展开全部
procedure 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;
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;
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询