Buenas Gente, encontre un problema con la liberacion de componenetes en tiempo de ejecución en el metodo TGridPanelLayout.ControlCollection.Clear que al parecer funciona bien bajo windows pero no bajo android, la idea es la siguiente tengo un TGridPanelLayout al cual le agrego varios TFrame creados a runtime por el metodo TGridPanelLayout.ControlCollection.AddControl. fito al codigo a continuacion a ver si ustedes ven algo que se me escapa, se me quemaron las neuronas renegando:
Este es el Tframe con su constructor personalizado
Código Delphi
[-]
unit UfrmFrameVientos;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
FMX.Objects, FMX.Controls.Presentation, FMX.Layouts;
type
TfrmFrameVientos = class(TFrame)
layVientoHoraXX: TLayout;
GridPanelLayout1: TGridPanelLayout;
Layout1: TLayout;
imgDirViento: TImage;
lbDireccion: TLabel;
Layout2: TLayout;
Rectangle1: TRectangle;
Rectangle2: TRectangle;
lbVelViento: TLabel;
lbHora: TLabel;
procedure FrameResize(Sender: TObject);
private
public
constructor create(AOwner:Tcomponent; AVel, ADir, AHora, AiconViento:String;
AColor: TAlphaColor); overload;
end;
implementation
{$R *.fmx}
uses UModuloDatos, FMX.MultiResBitmap;
constructor TfrmFrameVientos.create(AOwner: Tcomponent; AVel, ADir, AHora, AiconViento: String
;AColor: TAlphaColor);
var
fviento, porcentViento:real;
Item: TCustomBitmapItem;
Size: TSize;
begin
inherited create (AOwner);
fviento := strtofloat(AVel);
porcentViento := (fviento * 100)/118;
rectangle2.Size.Height := (porcentViento * rectangle1.Size.Height)/100;
imgDirViento.Width := (50 * layout1.Width)/100;
imgDirViento.Height := (50 * layout1.Height)/100;
lbDireccion.Text := ADir;
lbVelViento.Text := AVel;
lbHora.Text := AHora;
Rectangle2.Fill.Color := AColor;
ModuloDatos.listaImgViento.BitmapItemByName(AiconViento, Item, Size);
imgDirViento.Bitmap := Item.MultiResBitmap.Bitmaps[2.0];
end;
procedure TfrmFrameVientos.FrameResize(Sender: TObject);
begin
imgDirViento.Width := (50 * layout1.Width)/100;
imgDirViento.Height := (50 * layout1.Height)/100;
end;
end.
Y aca creo los frames y los agrego al TGridPanelLayout en este procedimiento, el agregar funcione de maravillas pero la limpieza de la lista no:
Código Delphi
[-]
procedure TfrmPrincipal.InsertarVientos;
var
i: integer;
ancho:Single;
UnFrame: TfrmFrameVientos;
begin
gridVientos.ControlCollection.Clear;
for i := 2 to 25 do
begin
UnFrame := TfrmFrameVientos.create(gridVientos,
ModuloDatos.pronosticoXhora[i].viento,
ModuloDatos.pronosticoXhora[i].dirViento,
ModuloDatos.pronosticoXhora[i].hora,
ModuloDatos.pronosticoXhora[i].iconViento,
ComboColorViento.Color);
UnFrame.Name := 'frame' + IntToStr(i);
UnFrame.Width := 60;
UnFrame.Parent := gridVientos;
gridVientos.ControlCollection.AddControl(UnFrame,-1,-1);
end;
Este es el error que da bajo solo android 8.0 y 6.0 segun pude probar: "A component named frmFrameVientos already exists"
Gracias por su tiempo.