Just a quick one, but the BoundsRect property getter in the FireMonkey TControl is incorrectly implemented, returning (0, 0, Width, Height) rather than (Position.X, Position.Y, Position.X + Width, Position.Y + Height). At first you might be tempted to say the property just has different semantics to the VCL version, however the implementation of the property setter gives the lie to that. Steps:
- Create a new FireMonkey HD application.
- Add a button to the form.
- Handle the button’s OnClick event like this:
procedure TForm1.Button1Click(Sender: TObject); begin Button1.BoundsRect := Button1.BoundsRect; end;
Expected: nothing to happen. Actual: the button moves to the top-left corner of the form.
To work around this bug, either don’t read BoundsRect in the first place (it is after all just a small utility property), or put the following class helper in scope:
type TControlHelper = class helper for TControl strict private function GetBoundsRect: TRectF; procedure SetBoundsRect(const Value: TRectF); public property BoundsRect: TRectF read GetBoundsRect write SetBoundsRect; end; //... function TControlHelper.GetBoundsRect: TRectF; begin Result.Left := Position.X; Result.Top := Position.Y; Result.Right := Result.Left + Width; Result.Bottom := Result.Top + Height; end; procedure TControlHelper.SetBoundsRect(const Value: TRectF); begin SetBounds(Value.Left, Value.Top, Value.Width, Value.Height); end;
Update 20/12/13: as pointed out in the comments, while GetBoundsRect remains as miscoded as ever in XE5, there is also a ParentedRect read-only property that does what the BoundsRect property getter should do. What a mess!