Reputation: 5251
I am building a application using FMX. This app will run on Windows, Mac OSX, and Linux.
I have a need to clone a TPanel
which is contained in another TPanel
.
Clone function provided in FMX is throwing an error:
Class TForm1 not found.
How to clone a TPanel
in an FMX app?
Here is the code I am using:
procedure TForm1.Button1Click(Sender: TObject);
var
CurrentControl, ClonedControl: TFMXObject;
CtlrNameCnt: String;
begin
CtlrNameCnt := IntToStr(Panel1.ControlsCount);
CurrentControl := Panel1;
ClonedControl := Clone(CurrentControl); //<- this gives error
ClonedControl.name := CurrentControl.name + '_' + CtlrNameCnt;
ClonedControl.Parent := Panel1;
end;
Upvotes: 1
Views: 560
Reputation: 5251
There were two major mistakes that I was making in my code.
Here is the code that works without any problem:
procedure TForm1.Button1Click(Sender: TObject);
var
CurrentControl, ClonedControl: TFMXObject;
CtlrNameCnt: String;
begin
CtlrNameCnt := IntToStr(Panel1.ControlsCount);
CurrentControl := Panel1;
ClonedControl := Panel2.Clone(CurrentControl); //<- this Works now!
ClonedControl.name := CurrentControl.name + '_' + CtlrNameCnt;
ClonedControl.Parent := Panel1;
end;
TIA
Yogi Yang
Upvotes: 1