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

Delphi FMX中TRectangle虚线边框动画失效问题求助

FMX虚线边框动画无效果问题排查与解决

关键错误原因

  • 属性名写错了:你要动画的StrokeDashOffset其实是TRectangle.Stroke的DashOffset子属性,所以PropertyName得写成'Stroke.DashOffset',不是'StrokeDashOffset'——这是动画不生效的核心原因。
  • 启动时机不对:在窗体OnCreate事件里启动动画,此时控件还没完成渲染初始化,动画可能没法正常触发。把启动代码移到OnShow事件里更稳妥。

修正后的代码

边框设置(可保留在OnCreate)

Rectangle1.Stroke.Kind := TBrushKind.Solid;
Rectangle1.Stroke.Dash := TStrokeDash.Dash;
Rectangle1.Stroke.Color := TAlphaColors.Red;
Rectangle1.Stroke.Thickness := 2;

// 配置动画参数(这里只改PropertyName)
FloatAnimation1.Parent := Rectangle1;
FloatAnimation1.PropertyName := 'Stroke.DashOffset'; // 修正属性路径
FloatAnimation1.StartValue := 0;
FloatAnimation1.StopValue := 20;
FloatAnimation1.Duration := 1;
FloatAnimation1.Loop := True;
FloatAnimation1.AnimationType := TAnimationType.InOut;
FloatAnimation1.Interpolation := TInterpolationType.Linear;

启动动画(移到FormShow事件)

procedure TForm1.FormShow(Sender: TObject);
begin
  FloatAnimation1.Start;
end;

额外检查项

  • 确认FloatAnimation1是设计时拖到窗体上的,或者代码里动态创建时正确分配了内存和Owner。
  • 检查FloatAnimation1.Enabled属性是否为True(默认是True,别被误改了)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 09:33:11