How to specify child padding/spacing to a TCustomControl in Lazarus?

In Delphi I could use Padding to specify how much spacing there would be between any child controls and my custom control. This is useful for example if the custom control has a caption section at the top and thus any aligned child controls would appear under the caption part, it's basically ensuring that child controls cannot be positioned or overlapping in parts of your control that you don't want them to be at.

I am trying to achieve this in Lazarus but as there is no Padding property I need some other alternative. The closest thing I found was ChildSizing but I cannot see an obvious way to implement it.

See this attached image:

The TMemo is child to my custom control and the way the spacing was achieved is like so:

constructor TMyControl.Create(AOwner: TComponent);
  inherited Create(AOwner);

  Self.ControlStyle := Self.ControlStyle + [csAcceptsControls];
  Self.BorderStyle  := bsSingle;
  Self.Height       := 210;  
  Self.Width        := 320;
  Self.ChildSizing.TopBottomSpacing := 10; // This line adds the spacing

As you can see from the attached image though, there is spacing at the top and bottom of the control which I expected to happen given the property name TopBottomSpacing.

There does not seem to be an obvious property that I can see to deal with simply adding spacing at the top, bottom, left or right independently:

How can I specify child spacing independently in Lazarus?

I can only see TopBottomSpacing and LeftRightSpacing which have the unwanted effect of adding spacing on the opposite sides, I only want to add padding/spacing at the top.


To specify the area to which are child controls can be anchored, override AdjustClientRect method like:

procedure TMyControl.AdjustClientRect(var ARect: TRect);
    inherited AdjustClientRect(ARect);
    ARect := Rect(
        ARect.Top + Canvas.TextHeight('A'), // Make place for control's header
    // Or just:
    // ARect.Top += Canvas.TextHeight('A');

Also keep in mind the warning from developers:

procedure TWinControl.AdjustClientRect(var ARect: TRect);
  // Can be overriden.
  // It's called often, so don't put expensive code here, or cache the result

Need Your Help

How to format decimals

ruby-on-rails ruby

I need to format float like price for two decimal places and thousands spaces, like this:

$.each with Ajax and Variable Modification

javascript jquery ajax closures

Why is whereString returning "where " and not "where "+some data. I know this has todo with closures and scoping but I'm not sure how to resolve it.