Delphi 10.2 FMX dynamicaly created panels doesn’t free [duplicate]

  

This question already has an answer here:

How to free a component in Android / iOS

3 answers

In an Android app, I dynamically create a number (depending on the choice of a user) of panels, each one has labels and other components in.
When the user’s choice changes, the application first releases the labels and then the panels, and repeats the process of adding new panels, etc.
In windows this works well but on the Android shows old and new panels as if I had never released the old ones.
The code looks like this :

var
forms : array of formaRec;
panels : array of TPanel;
labels,
Lvalues : array of TLabel;
buttons : array of Tspeedbutton;

procedure TTabbedForm.SGformvnSelectCell(Sender: TObject; const ACol, ARow: Integer; var CanSelect: Boolean);
var i,j, h : integer;
begin
for i := 0 to length(panels)-1 do begin
labels[i].Free;
Lvalues[i].Free;
buttons[i].Free;
panels[i].Free;
end;
setLength(panels,usersChoice);
setLength(Labels,usersChoice);
setLength(Lvalues,usersChoice);
setLength(buttons,usersChoice);
for i := 0 to length(panels)-1 do begin
panels[i] := TPanel.Create(nil);
with panels[i] do begin
parent := scrollBox1;
height := 100;
margins.Top := 3;
margins.Bottom := 3;
align := TAlignLayout.Top;
position.Y := 100000;
end;
buttons[i] := Tspeedbutton.Create(nil);
with buttons[i] do begin
parent := panels[i];
margins.Left := 3;
margins.Right := 5;
width := 25;
images := imageList1;
imageIndex := 0;
align := TAlignLayout.MostLeft;
end;
Labels[i] := TLabel.Create(nil);
with Labels[i] do begin
parent := panels[i];
height := 15;
margins.Left := 3;
margins.Right := 5;
align := TAlignLayout.MostTop;
textAlign := TtextAlign.leading;
VertTextAlign := TtextAlign.Trailing;
text := ‘field ‘+ inttostr(i);
textSettings.font.Style := [TFontStyle.fsBold,TFontStyle.fsUnderline];
textSettings.Fontcolor := TAlphaColorRec.red;
textSettings.WordWrap := TRUE;
end;
Lvalues[i] := TLabel.Create(nil);
with Lvalues[i] do begin
parent := panels[i];
height := 15;
margins.Left := 3;
margins.Right := 5;
align := TAlignLayout.client;
textAlign := TtextAlign.leading;
VertTextAlign := TtextAlign.Trailing;
textSettings.Fontcolor := TAlphaColorRec.maroon;
text := ‘value ‘+ inttostr(i);
end;

end;
end;
end;

Also, the font style and color doesn’t change to underline/red in windows and android platform.

Comments are closed.