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

推荐订阅源

爱范儿
爱范儿
量子位
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
J
Java Code Geeks
B
Blog
V
V2EX
博客园 - 三生石上(FineUI控件)
Blog — PlanetScale
Blog — PlanetScale
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
F
Fortinet All Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
A
About on SuperTechFans
D
DataBreaches.Net
阮一峰的网络日志
阮一峰的网络日志
博客园 - Franky
H
Help Net Security
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog
L
LangChain Blog

博客园 - 涂磊

TMS可以单独安装控件 02]AdvStringGrid中添加CheckBox 01]TMSadvStringGrid下载与安装 epson投影仪提示,保存时间的电池电量偏低,取消显示 用DeepSeek做的Delphi闹钟 XboxS联网下载完游戏后,要拔掉网线,就能玩游戏了 delphi10.3中Tmemo中某些文本显示下划线 delphi的TReeView支持鼠标拖动节点 cnPack里MarkDown里RTF显示 11]delphi中 RichEdit1设置行距 10]RichEdit另存 为BMP图片 09]delphi中richedit查找 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接收从文件管理器拖放过来的文件名
12]RichEdit某些文本突出显示
涂磊 · 2026-03-21 · via 博客园 - 涂磊

image

procedure TMainForm.ToolButton18Click(Sender: TObject);
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;

发表于 2026-03-21 14:02  涂磊  阅读(8)  评论()    收藏  举报