动态创建的THTMLabel.Height总是返回默认值?
我正在创建许多动态创建的 THTMLabels,但是在创建这些标签之后,当我尝试获取它的高度时,它总是返回默认高度值。
这是我的代码:
for i := 0 to ASentencePtr^.MUS.Count - 1 do
begin
j := Random(slTemp.Count);
sSen := ASentencePtr^.MUS.Strings[StrToInt(slTemp.Strings[j])] + ' / ';
THTMLabel.Create(Self).Name := 'lblSen_' + slTemp.Strings[j];
with THTMLabel(FindComponent('lblSen_' + slTemp.Strings[j])) do
begin
Font.Size := 18;
Font.Style := [fsBold];
Parent := FlowPanel1;
Width := Parent.Width;
Cursor := crHandPoint;
DragMode := dmAutomatic;
ControlStyle := ControlStyle + [csDisplayDragImage];
HTMLText.Add(sSen);
Autosizing := True;
end;
slTemp.Delete(j);
end;
现在,当我尝试访问 THTMLabel(FindComponent('lblSen_0')).Height 时,它仅返回默认值 17。我哪里出错了?有人有什么想法吗?非常感谢任何帮助,谢谢。
I am creating a number of dynamically created THTMLabels but after these are created,when I try to get it's height,it always return the default height value.
Here is my code:
for i := 0 to ASentencePtr^.MUS.Count - 1 do
begin
j := Random(slTemp.Count);
sSen := ASentencePtr^.MUS.Strings[StrToInt(slTemp.Strings[j])] + ' / ';
THTMLabel.Create(Self).Name := 'lblSen_' + slTemp.Strings[j];
with THTMLabel(FindComponent('lblSen_' + slTemp.Strings[j])) do
begin
Font.Size := 18;
Font.Style := [fsBold];
Parent := FlowPanel1;
Width := Parent.Width;
Cursor := crHandPoint;
DragMode := dmAutomatic;
ControlStyle := ControlStyle + [csDisplayDragImage];
HTMLText.Add(sSen);
Autosizing := True;
end;
slTemp.Delete(j);
end;
Now when I try to access THTMLabel(FindComponent('lblSen_0')).Height, it returns only the default value which is 17. Where have I gone wrong? Any thoughts anyone? Any help is greatly appreciated, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们遇到了同样的问题,但设法使用 THTMLStaticText 组件和这个在动态(高度)调整时计算高度的函数解决了这些问题:
该函数需要一个 TLabel 组件,专门用于计算目的(您可以将可见性设置为 false)。 htmlStaticText 组件应将 AutoSize 设置为 true(在我们的示例中,AutoSizeType 设置为 asVertical),并且在调用该函数时应存在 htmlStaticText.Text。
We had the same problems but managed to solve them with the THTMLStaticText component and this function that calculates the height when dynamically (height) adjusted:
The function requires a TLabel component, used exclusively for calculation purposes (you can set the visibility to false). The htmlStaticText component should have AutoSize set to true (in our case AutoSizeType is set to asVertical) and the htmlStaticText.Text should be present when calling the function.
我认为
THTMLLabel
是 Jedi Library 的一部分,不是吗?这个问题很奇怪。我不知道该控件的实现,但如果您遇到此问题,则可能是 AutoSize 属性的实现非常糟糕。如果您无法检查并修复此控件的源,请尝试使用 BoundsRect 属性来获取高度:
I think
THTMLLabel
is part of the Jedi Library, itsn't? This problem is weird. I don't know the implementation of this control, but if you are having this problem, then there's may be a very bad implementation of the AutoSize Property.If you can't inspect and fix the source of this control, try to use the BoundsRect property to get the height: