Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   FireMonkey (https://www.clubdelphi.com/foros/forumdisplay.php?f=50)
-   -   TGridPanelLayout.ControlCollection.Clear no parece funcionar en Android (https://www.clubdelphi.com/foros/showthread.php?t=94753)

Esteban74 24-06-2020 08:21:15

TGridPanelLayout.ControlCollection.Clear no parece funcionar en Android
 
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
    { Private declarations }
  public
   constructor create(AOwner:Tcomponent; AVel, ADir, AHora, AiconViento:String;
                     AColor: TAlphaColor); overload;
  end;

implementation

{$R *.fmx}

uses UModuloDatos, FMX.MultiResBitmap;

{ TfrmFrameVientos }

///////////////////////////////////////////////////////////////////////////
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

 //Limpio la lista de vientos (AL parecer falla en Android)
 gridVientos.ControlCollection.Clear;

 // Agrego los frames al panelGridlayout inccrustado en un THorzScrollBox
 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.

Esteban74 24-06-2020 18:49:28

Bueno encontre una forma que funciona parece sin problemas en android, desconozco el por que ya que aun no tengo conocimientos profundos del modelo de objetos firemonkey, cito el codigo que funciona a continuacion por si a alguien le paso anteriormente:

Código Delphi [-]
procedure TfrmPrincipal.InsertarVientos;
var
 i: integer;
 UnFrame: TfrmFrameVientos;
begin

 //Limpio la lista de vientos (Al parecer falla en Android)

 // gridVientos.ControlCollection.Clear; <<<------ Esto no parece funcionar bien 

 //Recorriendo las columnas usando DisposeOf y parece funcionar en
 //   todas las plataformas

 for i := gridVientos.ControlsCount - 1 downto 0 do
  begin
   gridVientos.ControlCollection.Controls[i,0].DisposeOf;
  end;

 // Agrego los frames al panelGridlayout inccrustado en un THorzScrollBox
 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;
end;


La franja horaria es GMT +2. Ahora son las 08:58:02.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi