Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > FireMonkey
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 24-06-2020
Esteban74 Esteban74 is offline
Miembro
 
Registrado: jun 2020
Posts: 12
Poder: 0
Esteban74 Va por buen camino
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.
Responder Con Cita
  #2  
Antiguo 24-06-2020
Esteban74 Esteban74 is offline
Miembro
 
Registrado: jun 2020
Posts: 12
Poder: 0
Esteban74 Va por buen camino
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;
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Datetimepicker.clear Osorio OOP 5 27-07-2017 17:13:04
Orden Clear me manda de nuevo al pricipio del procedimiento alexglez1255 Conexión con bases de datos 3 12-04-2015 04:36:05
Como Puedo Programar un Button como Clear darnnezt Varios 4 05-02-2011 08:03:13
Mi ejecutable parece no funcionar - AYUDA!! Rowerto Varios 2 16-06-2010 11:21:27
simular en un DBLookupcombobox el efecto de un DBedit.clear el_barto Varios 4 11-08-2007 01:57:20


La franja horaria es GMT +2. Ahora son las 20:58:35.


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
Copyright 1996-2007 Club Delphi