6

I have tried to embed a form inside a Scrollbox:

procedure TfrmMain.FormCreate(Sender: TObject);
var
  Control:TControlView;
begin
  Control := TControlView.Create(Self);
  Control.BorderIcons := [];
  Control.parent := ListControls;
  Control.width := 800;
  ListControls.AddObject(Control);
  Control.Visible:= True;
end;

However the form is displayed behind tfrmMain and outside the bouns of the form.

My idea is put a form inside a panel, and both inside scrollbox. Each form represent a complex item with several controls and stuff (the reason to not use ListBox? Firemonkey control creation is far harder than simply do a form and embed it)

Johan
  • 74,508
  • 24
  • 191
  • 319
mamcx
  • 15,916
  • 26
  • 101
  • 189

3 Answers3

7

The secret is in how you design your child form.

You need to create a control as a container, say a TLayout (no styling), TRectangle (Basic styling) or TPanel. I'd go with the TLayout. Decide on a name for your container, say 'Container' for the sake of argument. Now create you child form and simply assign the Parent of Container to your parent object.

So, from your code above (I'm assuming TControlView is your child form):

procedure TfrmMain.FormCreate(Sender: TObject);
var
  Control:TControlView;
begin
  Control := TControlView.Create(Self);
  Control.Container.parent := ListControls;
  Control.Container.width := 800;
end;
Mike Sutton
  • 4,191
  • 4
  • 29
  • 42
  • Still the same issue. When your say " how you design your child form" mean something different to use a tForm?? TControlView is a form in my code right now. – mamcx Jan 28 '12 at 21:59
  • What type is ListControls? Also, you may want to play with Container.Align. – Mike Sutton Jan 29 '12 at 00:35
  • And with what Align values? Note that alNone is not constrained to appear within it's parent client area. BTW I don't have much experience with TScrollBox - stick with TLayout or TPanel for now. If that doesn't fix it post more code. – Mike Sutton Jan 30 '12 at 18:01
  • The problem is Forms have not Align properties. The code that I have is the one I posted... – mamcx Jan 30 '12 at 18:18
  • So, you've ignored all the advice I've given so far? – Mike Sutton Jan 31 '12 at 09:56
  • Then I don't understand this (english no my main language). With "The secret is in how you design your child form" I imagine that the control to be embebed (and that is the question, too) is a form. If the suggestion is put any other control, then yes, that works, but get lost the ability to use the IDE to design them. – mamcx Jan 31 '12 at 20:38
  • You can't assign a forms parent to another control. You can assign any control on that forms parent to another control. Just put your controls inside another control (which I call Container), set it's align to alClient (the Container) and it will work. I'm not sure about you comment about design time. You can edit each form separately, but you can't edit both together. – Mike Sutton Feb 01 '12 at 17:59
  • Aahhh, my mistake. Now I understand.. Is a container on top of the form and the container change of the parent, but the form is not touched. Is clear now I get it. Thanks for your patience.. – mamcx Feb 02 '12 at 02:08
0

You have to set the container control's ClipChildren property to true.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
nexial
  • 399
  • 1
  • 3
  • 7
0

Here is a step by step instruction:

  1. Design your embedded form. Place a TLayout with alignment alClient onto your form. Place all controls inside this layout:

    TFormEmbedded = class(TForm)
        LayoutMain: TLayout;
        //....
    end;
    
  2. Design your master form.

  3. Place a Layout onto your master form, that shall later contain the subform.

  4. Add the following code to FormCreate of your master form:

    procedure TFormMaster.FormCreate(Sender: TObject);
    var
        SubForm: TFormEmbedded;
    begin
        SubForm := TFormEmbedded.Create(Self);
        SubForm.LayoutMain.Parent := Self.LayoutSubForm;
    end;
    

Thanks to nexial for the original description.

Community
  • 1
  • 1
yonojoy
  • 5,486
  • 1
  • 31
  • 60