I'm trying to use the overloaded function of SetBounds
in FMX.Forms, passing Screen.Displays[index].BoundsRect
as a parameter. However, since Delphi 11 BoundsRect
seems to return a TrectF
rather than Trect
.
I'm looking for a way to convert this TrectF
to a Trect
so that I can pass it with setBounds
.
Any help would be greatly appreciated.
CodePudding user response:
The only difference between TRect
and TRectF
is that TRect
is storing its coordinates as integer values while TRectF
is storing its coordinates as floating point values. So, all you have to do is convert floating point values stored in TRectF
into integers by doing something like this:
Rect.Left := Round(RectF.Left);
Rect.Right := Round(RectF.Right);
Rect.Top := Round(RectF.Top);
Rect.Bottom := Round(RectF.Bottom);
NOTE: Based on your case scenario, you might want to use two other rounding methods that are available in the System.Math
unit: Floor()
or Ceil()
.
CodePudding user response:
@SilverWarrior's answer explains how to convert TRectF
to TRect
so you can use it with TForm.SetBounds()
.
I just want to mention that Delphi 11 also introduced a new SetBoundsF()
method in TForm
, which takes floating point coordinates instead of integer coordinates. And it is overloaded to accept TRectF
.
So, you don't need to convert the coordinates from floating points to integers at all. You just need to update your lpgonlc to call a different method instead.