Author: William Gerbert
I have a TDBText with WordWrap = True and it is anchored to the left and right of
the form. As the form resizes, the height of the TDBText changes. Is there any way
of knowing the height of the TDBText? TDBText.Height doesn't return the correct
value.
Answer:
TDBText is a descendant of TCustomLabel, so this should work:
1 2 { ... }3 type4 TLabelCracker = class(TCustomLabel)
5 end;
6 7 function LabelTextHeight(ALabel: TCustomLabel): Integer;
8 const9 WordWraps: array[Boolean] of Word = (0, DT_WORDBREAK);
10 var11 Rect: TRect;
12 begin13 Rect := ALabel.ClientRect;
14 TLabelCracker(ALabel).DoDrawText(Rect, (DT_EXPANDTABS or DT_CALCRECT) or15 WordWraps[TLabelCracker(ALabel).WordWrap]);
16 Result := Rect.Bottom - Rect.Top;
17 end;