title: Simulate Align position in Delphi Custom Panel
body: <p>I'm building a custom panel in Delphi XE5 and I'm having a hard time simulating a new <strong>"Gravity"</strong> property where I can combine two coordinates (like Right + Bottom) and the effect is similar to "Align" however, it does not resize the object, direction. The main problem I encountered is to simulate this behavior. My initial intention was to create a panel in memory with the same "Parent" in my custom panel and then align to the position defined in "Gravity" overwriting the "SetBounds" method. It's working, but a bit precarious, especially in "Design Time". <strong>Could someone suggest me how to more effectively simulate this alignment using VCL?</strong></p>
  
  <pre><code>function TZPanel.GetPosition: TCustomPanel;
      var
        sid: TZSide;
        anch: TAnchors;
        panTest: TPanel;
        function getGravity(al: TAlign): TRect;
        var
          panGravity: TPanel;
          I: Integer;
        begin
          try
            //Self.Visible := False;
  
            panGravity:= TPanel.Create(Self);
            panGravity.BevelInner  := panTest.BevelInner;
            panGravity.BevelOuter  := panTest.BevelOuter;
            panGravity.BevelWidth  := panTest.BevelWidth;
            panGravity.BorderWidth := panTest.BorderWidth;
            panGravity.ParentBackground := True;
            panGravity.SetBounds(panTest.Left, panTest.Top, panTest.Width, panTest.Height);
            panGravity.Parent:= Self.Parent;
            panGravity.Align := al;
  
            Result:= panGravity.BoundsRect;
          finally
            panGravity.Destroy;
            Self.Visible := True;
          end;
        end;
  
      begin
        panTest := TPanel.Create(Self);
        panTest.Align   := Align;
        panTest.Anchors := Anchors;
        panTest.BevelInner  := BevelInner;
        panTest.BevelOuter  := BevelOuter;
        panTest.BevelWidth  := BevelWidth;
        panTest.BorderWidth := BorderWidth;
        panTest.SetBounds(Left, Top, Width, Height);
  
        if (FGravity = []) then
        begin
          //
        end
        else
        begin
          panTest.Align := alCustom;
          anch := [];
  
          for sid in FGravity do
          begin
            case sid of
              sTop:
              begin
                panTest.Top := getGravity(alTop).Top;
                anch := anch + [akTop];
              end;
  
              sRight:
              begin
                panTest.Left := getGravity(alRight).Left;
                anch := anch + [akRight];
              end;
  
              sBottom:
              begin
                panTest.Top := getGravity(alBottom).Top;
                anch := anch + [akBottom];
              end;
  
              sLeft:
              begin
                panTest.Left := getGravity(alLeft).Left;
                anch := anch + [akLeft];
              end;
            end;
          end;
          panTest.Anchors := anch;
        end;
        Result := panTest;
      end;
  </code></pre>