Raffaele Rossi
Raffaele Rossi

Reputation: 3137

Delphi clone layout

I have made an android app with Delphi but I have a weird behavior. This is the situation.

enter image description here

I have a TLayout (called InputLayout) and it contains a GridPanelLayout. I have to copy this grid inside the InputLayout but I get this result:

enter image description here

Of course the result that I have is the one on the left. You can see that this is not what I am looking for because I would like to have an exact copy of the grid above. The final result must be two GridPanelLayout where the second is placed below the first. This is the code:

procedure TForm1.Button3Click(Sender: TObject);
var c: TGridPanelLayout;
begin

 try

  c := TGridPanelLayout(InputLayout.Children[0].Clone(InputLayout));
  c.Align := TAlignLayout.Top;
  InputLayout.AddObject(c);

 except

  // ... 

 end;

end;

What is wrong? Please note that InputLayout is the layout that contains the GridPanelLayout and that component is the only one, so I can access safely with the 0 index.

Upvotes: 0

Views: 877

Answers (1)

Alberto Miola
Alberto Miola

Reputation: 4751

I think that you cannot use a TGridPanelLayout because it seems that there is something wrong with that component. I am using Delphi Tokyo Starter and I have found this solution to your problem.

  1. Drop a VertScrollBox (or a TLayout or a HorzScrollBox)
  2. Put a TGridLayout outside the the VertScrollBox
  3. Add in the GridLayout what you need for example a TEdit or a TLabel
  4. Set TGridLayout.Visible := false; because you are using this as "template". I will make a copy of this and the clone will be added in the InputLayout.

A TGridLayout works on Windows but I guess that it will work on Android and iOS as well (I can't test it with starter). Add an event handler to a button like this:

//Button1 onclick
for i := 1 to max do
   begin
    c := (GridLayout1.Clone(Owner) as TGridLayout);
    (c as TGridLayout).Visible := True;
    (c as TGridLayout).Parent := InputLayout;
    InputLayout.AddObject(c);
   end;

Here there is an integer variable called max which of course indicates how many children you are going to create inside InputLayout. It isn't really needed if you have to make a single copy, but I am giving you this loop just in case you change your mind. Here you have the result:

enter image description here

Here you see 3 TEdit components but you had a TLabel, a TEdit and a TButton. What to do? Simply revert the TGridLayout visibility to True, add whatever you want (in this case a label, an edit and a button) and set the Visible poperty to false again.

Upvotes: 1

Related Questions