You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Delphi TMS WEB Core中通过代码为TWebLabel添加下划线?

在Delphi TMS WEB Core中为TWebLabel添加下划线的正确代码实现方式

问题背景

设计时可通过属性设置为TWebLabel添加下划线效果,但运行时使用常规Font.Style设置无法正常显示,尝试以下三种方式均未解决:

  • WebLinkLabel1.Font.Style.fsUnderline := True;:报错[Error] illegal qualifier "." after "Style:set of TFontStyle"
  • WebLinkLabel1.Font.Style := fsUnderline;:报错[Error] Incompatible types: got "TFontStyle" expected "set of TFontStyle"
  • WebLinkLabel1.Font.Style := [fsUnderline];:无编译错误,但标签仍不显示下划线

正确实现方式

方法1:通过Font.Style设置并强制刷新样式

设置Font.Style后,需要调用控件的UpdateStyle方法将样式同步到前端DOM,代码如下:

WebLinkLabel1.Font.Style := [fsUnderline];
WebLinkLabel1.UpdateStyle;

方法2:直接操作HTML元素的CSS样式

由于TWebLabel底层基于HTML元素,可直接修改其CSS属性来添加下划线,这种方式更直接且无需额外刷新:

// 方式A:直接赋值样式属性
WebLinkLabel1.ElementHandle.style.textDecoration := 'underline';

// 方式B:使用setProperty方法
WebLinkLabel1.ElementHandle.style.setProperty('text-decoration', 'underline');

若需要移除下划线,只需将对应值改为'none',或设置WebLinkLabel1.Font.Style := []后调用UpdateStyle即可。

内容的提问来源于stack exchange,提问作者Shaun Roselt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 06:22:47