惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
V
V2EX
博客园 - 【当耐特】
WordPress大学
WordPress大学
爱范儿
爱范儿
美团技术团队
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
小众软件
小众软件
量子位
Hugging Face - Blog
Hugging Face - Blog
B
Blog RSS Feed
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 聂微东
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
博客园 - 叶小钗
GbyAI
GbyAI
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
F
Full Disclosure
G
Google Developers Blog
D
Docker
T
Tailwind CSS Blog
C
Check Point Blog
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
B
Blog
博客园 - 三生石上(FineUI控件)
博客园 - Franky
H
Help Net Security
MyScale Blog
MyScale Blog
U
Unit 42
D
DataBreaches.Net
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
L
LangChain Blog
有赞技术团队
有赞技术团队
Martin Fowler
Martin Fowler
Microsoft Security Blog
Microsoft Security Blog

博客园 - 涂磊

02]AdvStringGrid中添加CheckBox 01]TMSadvStringGrid下载与安装 epson投影仪提示,保存时间的电池电量偏低,取消显示 用DeepSeek做的Delphi闹钟 XboxS联网下载完游戏后,要拔掉网线,就能玩游戏了 12]RichEdit某些文本突出显示 delphi10.3中Tmemo中某些文本显示下划线 delphi的TReeView支持鼠标拖动节点 cnPack里MarkDown里RTF显示 11]delphi中 RichEdit1设置行距 10]RichEdit另存 为BMP图片 08]delphi10.3剪贴板的图片,保存到文件 07]Delphi10.3中Richedit中的链接可以点击 06]delphi10.3中richedit中文本背景颜色 05]delphi10.3中richedit中删除线 delphi10.3中UpDown1使用 04]RichEdit的上标和下标,Delphi10.3 03]RichEdit插入BMP图片 delphi 中tButtonColor颜色选择 02]如何设置RichEdit文本颜色?_编程语言-CSDN问答 01]delphi从TRichEdit获得RTF格式文本(PC版本) Delphi10.3接收从文件管理器拖放过来的文件名
09]delphi中richedit查找
涂磊 · 2026-02-18 · via 博客园 - 涂磊
放置组件:在窗体上放置一个 TRichEdit (如 RichEdit1)、一个 TButton (如 Button1) 和一个 TFindDialog (如 FindDialog1)。
设置按钮事件:在按钮的 OnClick 事件中调用查找对话框。
procedure TForm1.Button1Click(Sender: TObject);
begin
  // 可选:将对话框显示在 RichEdit 旁边
  FindDialog1.Position := Point(RichEdit1.Left + RichEdit1.Width, RichEdit1.Top);
  FindDialog1.Execute; // 显示查找对话框
end;
//处理查找事件:在 TFindDialog 的 OnFind 事件中编写核心的查找逻辑。当用户在查找对话框中点击“查找下一个”时,此事件会被触发。
procedure TForm1.FindDialog1Find(Sender: TObject);
var
  FoundAt: LongInt;
  StartPos, ToEnd: Integer;
  SearchOptions: TSearchTypes;
begin
  // 初始化搜索选项
  SearchOptions := [];
  with FindDialog1 do
  begin
    if frMatchCase in Options then
      SearchOptions := SearchOptions + [stMatchCase];
    if frWholeWord in Options then
      SearchOptions := SearchOptions + [stWholeWord];
  end;

  with RichEdit1 do
  begin
    // 确定搜索的起始位置
    // 如果有选中的文本,则从选中内容之后开始查找,避免重复找到同一个词
    if SelLength > 0 then
      StartPos := SelStart + SelLength
    else
      StartPos := 0;

    // 计算从起始位置到文本末尾的长度
    ToEnd := Length(Text) - StartPos;

    // 执行查找
    FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, SearchOptions);

    // 处理查找结果
    if FoundAt <> -1 then
    begin
      // 找到:选中文本,并让 RichEdit 获得焦点以高亮显示
      SetFocus;
      SelStart := FoundAt;
      SelLength := Length(FindDialog1.FindText);
    end
    else
    begin
      // 未找到:发出提示音或显示消息
    //  Beep;
      // 或者 MessageBeep(0);
      // 更友好的方式:
     ShowMessage(Format('未找到 "%s"。', [FindDialog1.FindText]));
    end;
  end;
end;

 Delphi RichEdit用RichEdit1.FindText关键词红色高亮

var
  FoundPos: Integer;
  SearchText: string;
  StartPos: Integer;
  SearchOptions: TSearchTypes;
begin
  SearchText := Edit2.Text;
  if SearchText = '' then Exit;

  // 先重置所有文本颜色为黑色
  editor.SelStart := 0;
  editor.SelLength := Length(editor.Text);
  editor.SelAttributes.Color := clBlack;

  // 设置查找选项
  SearchOptions := [stMatchCase]; // 根据需要添加选项

  StartPos := 0;
  while True do
  begin
    // 从 StartPos 开始查找
    FoundPos := editor.FindText(
      SearchText,
      StartPos,
      Length(editor.Text) - StartPos,
      SearchOptions
    );

    if FoundPos = -1 then
      Break; // 没找到就退出

    // 高亮找到的词
    editor.SelStart := FoundPos;
    editor.SelLength := Length(SearchText);
    editor.SelAttributes.Color := clRed;

    // 移动起始位置,继续往后找(跳过已找到的词)
    StartPos := FoundPos + Length(SearchText);

    // 防止死循环(如果关键词长度为0)
    if Length(SearchText) = 0 then
      Break;
  end;

  // 取消选中状态
  editor.SelLength := 0;
  editor.SelStart := 0;
end;