ActiveDelphi - Índice do Fórum ActiveDelphi
.: O site do programador Delphi! :.
 
 FAQFAQ   PesquisarPesquisar   MembrosMembros   GruposGrupos   RegistrarRegistrar 
 PerfilPerfil   Entrar e ver Mensagens ParticularesEntrar e ver Mensagens Particulares   EntrarEntrar 

Controlando TFrames [RESOLVIDO]

 
Novo Tópico   Responder Mensagem    ActiveDelphi - Índice do Fórum -> Mobile com Delphi
Exibir mensagem anterior :: Exibir próxima mensagem  
Autor Mensagem
flexsistemas
Aprendiz
Aprendiz


Registrado: Terça-Feira, 29 de Outubro de 2013
Mensagens: 121
Localização: Caxias do Sul

MensagemEnviada: Seg Ago 11, 2014 11:23 am    Assunto: Controlando TFrames [RESOLVIDO] Responder com Citação

Bom dia Pessoal,

Estou iniciando um novo projeto com o XE6 com Firemonkey e não quero trabalhar com Forms e sim com Frames pois penso que fica mais fácil de portar para dispositivos móveis.

Então tenho um form principal e dentro dele tem um panel que chamei de área de trabalho e é ele que fica como parent dos meus frames.

A pergunta é posso controlar esses frames em um LIST?

Queria criar um class procedure passando como parametro a classe do frame e ele criaria ele para mim.

Ex.

Cadastro Cidade - TFme_Cidades = class(TFme_Pai)
Cadastro Pessoas - TFme_Clientes = class(TFme_Pai)
Cadastro Produtos - TFme_Produtos = class(TFme_Pai)
Cadastro Pedidos - TFme_Pedidos = class(TFme_Pai)

Frm_Principal que tem a chamada para esses frames
Voltar ao Topo
Ver o perfil de Usuários Enviar Mensagem Particular Enviar E-mail Visitar a homepage do Usuário MSN Messenger
flexsistemas
Aprendiz
Aprendiz


Registrado: Terça-Feira, 29 de Outubro de 2013
Mensagens: 121
Localização: Caxias do Sul

MensagemEnviada: Qui Ago 14, 2014 11:42 am    Assunto: Responder com Citação

Resolvi da seguinte maneira:

Código:

unit UFmeFrameBase;

interface

uses
  FMX.Forms,
//  Data.Bind.DBScope,
  System.Classes;

type
  TFme_FrameBase = class(TFrame)
  private
    { Private declarations }
    FPreencheAreaTrabalho: Boolean;
    FTituloFrame: String;
    procedure SetPreencheAreaTrabalho(const Value: Boolean);
//  protected
//    { Private declarations }
//    FBindSourceDB: TBindSourceDB;
//    function GetBindSourceDB: TBindSourceDB; Virtual;
  public
    { Public declarations }
//    property BindSourceDB: TBindSourceDB read GetBindSourceDB;
    property TituloFrame: String read FTituloFrame write FTituloFrame;
    property PreencheAreaTrabalho: Boolean read FPreencheAreaTrabalho write SetPreencheAreaTrabalho;

    constructor CreateFrame(AOwner: TComponent; const pPreencheAreaTrabalho: Boolean); virtual;
  end;

  TListaFrameBase = class
  private
    { private declarations }
    FLista: TList;
    FFrameAtivo: TFme_FrameBase;
    procedure SetFrameAtivo(const Value: TFme_FrameBase);
  protected
    { protected declarations }
  public
    { public declarations }
    property FrameAtivo: TFme_FrameBase read FFrameAtivo write SetFrameAtivo;

    constructor Create;
    destructor Destroy; override;

    procedure ApresentaFrame;
    procedure EsconderFrames;
    procedure AtivarFrame(const pFrameIdx: Integer);
    procedure AtivarProximoFrame(const pFrameIdx: Integer);
    function LocalizarFrame(const pFrameName: String): TFme_FrameBase;

    procedure LimparFrames;
    procedure Adicionar(pFme_FrameBase: TFme_FrameBase);
    procedure Remover(const pNroFrame: Integer);
    function NroFrames: Integer;
  end;

implementation

{$R *.fmx}

uses
  UFrmPrincipal,
  UFuncoesVisuais,
  System.SysUtils,
  System.UITypes,
  UFuncoesValores,
  UFuncoesSistema;

{ TFme_FrameBase }

constructor TFme_FrameBase.CreateFrame(AOwner: TComponent; const pPreencheAreaTrabalho: Boolean);
begin
  inherited Create(AOwner);
  Parent := Frm_Principal.Pnl_AreaDeTrabalho;
  PreencheAreaTrabalho := pPreencheAreaTrabalho;
end;

//function TFme_FrameBase.GetBindSourceDB: TBindSourceDB;
//begin
//  if not Assigned(FBindSourceDB) then
//    FBindSourceDB := TBindSourceDB.Create(Self);
//  Result := FBindSourceDB;
//end;

procedure TFme_FrameBase.SetPreencheAreaTrabalho(const Value: Boolean);
begin
  FPreencheAreaTrabalho := Value;
  TFuncoesVisuais.AjustaFrameAoParent(Frm_Principal.Pnl_AreaDeTrabalho, Self, FPreencheAreaTrabalho);
end;

{ TListaFrameBase }

procedure TListaFrameBase.Adicionar(pFme_FrameBase: TFme_FrameBase);
begin
  try
    FFrameAtivo := nil;
    EsconderFrames;
    FLista.Add(pFme_FrameBase);
    pFme_FrameBase.Tag := FLista.Count;
    FFrameAtivo := pFme_FrameBase;
    ApresentaFrame;
  finally
    Frm_Principal.Act_FecharJanela.Enabled := not TFuncoesValores.ValorVazio(Frm_Principal.ListaFrameBase.NroFrames);
    Frm_Principal.Act_FecharJanela.Visible := Frm_Principal.Act_FecharJanela.Enabled;
    Frm_Principal.Act_ProximaJanela.Enabled := (Frm_Principal.ListaFrameBase.NroFrames > 1);
    Frm_Principal.Act_ProximaJanela.Visible := Frm_Principal.Act_ProximaJanela.Enabled;
  end;
end;

constructor TListaFrameBase.Create;
begin
  inherited Create;

  FFrameAtivo := nil;

  FLista := TList.Create;
  FLista.Clear;
end;

destructor TListaFrameBase.Destroy;
begin
  LimparFrames;

  if Assigned(FLista) then
    FreeAndNil(FLista);

  inherited Destroy;
end;

procedure TListaFrameBase.EsconderFrames;
var
  lIdx: Integer;
  lFme_FrameBase: TFme_FrameBase;
begin
  for lIdx := 0 to FLista.Count -1 do
  begin
    lFme_FrameBase := TFme_FrameBase(FLista[lIdx]);
    if Assigned(lFme_FrameBase) then
    begin
      lFme_FrameBase.Enabled := False;
      lFme_FrameBase.Visible := lFme_FrameBase.Enabled;
      if not lFme_FrameBase.Visible then
      begin
        lFme_FrameBase.Hide;
        lFme_FrameBase.SendToBack;
      end;
    end;
  end;
end;

function TListaFrameBase.NroFrames: Integer;
var
  lIdx: Integer;
  lFme_FrameBase: TFme_FrameBase;
begin
  Result := 0;
  for lIdx := 0 to FLista.Count -1 do
  begin
    lFme_FrameBase := TFme_FrameBase(FLista[lIdx]);
    if Assigned(lFme_FrameBase) then
      Inc(Result);
  end;
end;

procedure TListaFrameBase.LimparFrames;
var
  lIdx: Integer;
  lFme_FrameBase: TFme_FrameBase;
begin
  for lIdx := 0 to FLista.Count -1 do
  begin
    lFme_FrameBase := TFme_FrameBase(FLista[lIdx]);
    if Assigned(lFme_FrameBase) then
      lFme_FrameBase.Free;
  end;
  FLista.Clear;
end;

procedure TListaFrameBase.Remover(const pNroFrame: Integer);
var
  lIdx: Integer;
  lFme_FrameBase: TFme_FrameBase;
begin
  try
    lFme_FrameBase := nil;

    for lIdx := 0 to FLista.Count -1 do
    begin
      lFme_FrameBase := TFme_FrameBase(FLista[lIdx]);

      if Assigned(lFme_FrameBase) and (lFme_FrameBase.Tag = pNroFrame) then
      begin
        FreeAndNil(lFme_FrameBase);
        FLista.Delete(lIdx);
        AtivarProximoFrame(lIdx);
        Break;
      end;
    end;
  finally
    Frm_Principal.Act_FecharJanela.Enabled := not TFuncoesValores.ValorVazio(Frm_Principal.ListaFrameBase.NroFrames);
    Frm_Principal.Act_FecharJanela.Visible := Frm_Principal.Act_FecharJanela.Enabled;
    Frm_Principal.Act_ProximaJanela.Enabled := (Frm_Principal.ListaFrameBase.NroFrames > 1);
    Frm_Principal.Act_ProximaJanela.Visible := Frm_Principal.Act_ProximaJanela.Enabled;
  end;
end;

procedure TListaFrameBase.SetFrameAtivo(const Value: TFme_FrameBase);
begin
  EsconderFrames;
  FFrameAtivo := Value;
  ApresentaFrame;
end;

procedure TListaFrameBase.ApresentaFrame;
begin
  if Assigned(FFrameAtivo) then
  begin
    FFrameAtivo.Enabled := True;
    FFrameAtivo.Visible := FFrameAtivo.Enabled;
    FFrameAtivo.Show;
    FFrameAtivo.BringToFront;
    Frm_Principal.Lbl_DescricaoAplicativo.Text := FFrameAtivo.TituloFrame;
    Frm_Principal.Lbl_FundoDescricaoAplicativo.Text := Frm_Principal.Lbl_DescricaoAplicativo.Text;
    Frm_Principal.Lbl_DescricaoAplicativo.TextSettings.FontColor := TAlphaColorRec.Green;
  end
  else
  begin
    Frm_Principal.Lbl_DescricaoAplicativo.Text := Frm_Principal.Caption;
    Frm_Principal.Lbl_FundoDescricaoAplicativo.Text := Frm_Principal.Lbl_DescricaoAplicativo.Text;
    Frm_Principal.Lbl_DescricaoAplicativo.TextSettings.FontColor := TAlphaColorRec.Blue;
  end;
  TFuncoesSistema.AtualizaAplicacao;
end;

function TListaFrameBase.LocalizarFrame(const pFrameName: String): TFme_FrameBase;
var
  lIdx: Integer;
  lFme_FrameBase: TFme_FrameBase;
begin
  Result := nil;
  for lIdx := 0 to FLista.Count -1 do
  begin
    lFme_FrameBase := TFme_FrameBase(FLista[lIdx]);
    if Assigned(lFme_FrameBase) and (lFme_FrameBase.Name = pFrameName) then
    begin
      Result := lFme_FrameBase;
      Break;
    end;
  end;
end;

procedure TListaFrameBase.AtivarFrame(const pFrameIdx: Integer);
var
  lIdx: Integer;
  lAchou: Boolean;
  lFrame: TFme_FrameBase;
begin
  lFrame := nil;
  lAchou := False;

  for lIdx := 0 to FLista.Count -1 do
  begin
    lFrame := TFme_FrameBase(FLista[lIdx]);
    lAchou := Assigned(lFrame) and (lFrame.Tag = pFrameIdx);
    if lAchou then
      Break;
  end;

  if lAchou and Assigned(lFrame) then
    FrameAtivo := lFrame;
end;

procedure TListaFrameBase.AtivarProximoFrame(const pFrameIdx: Integer);
var
  lIdx: Integer;
  lFrame: TFme_FrameBase;
  lAchou: Boolean;
begin
  lAchou := False;

  for lIdx := 0 to FLista.Count -1 do
  begin
    lFrame := TFme_FrameBase(FLista[lIdx]);
    lAchou := Assigned(lFrame) and (lFrame.Tag > pFrameIdx);
    if lAchou then
    begin
      FrameAtivo := lFrame;
      Break;
    end;
  end;

  if not lAchou then
  begin
    lAchou := False;
    for lIdx := 0 to FLista.Count -1 do
    begin
      lFrame := TFme_FrameBase(FLista[lIdx]);
      lAchou := Assigned(lFrame);
      if lAchou then
      begin
        FrameAtivo := lFrame;
        Break;
      end;
    end;

    if not lAchou then
     FrameAtivo := nil;
  end;
end;

end.
Voltar ao Topo
Ver o perfil de Usuários Enviar Mensagem Particular Enviar E-mail Visitar a homepage do Usuário MSN Messenger
Mostrar os tópicos anteriores:   
Novo Tópico   Responder Mensagem    ActiveDelphi - Índice do Fórum -> Mobile com Delphi Todos os horários são GMT - 3 Horas
Página 1 de 1

 
Ir para:  
Enviar Mensagens Novas: Proibido.
Responder Tópicos Proibido
Editar Mensagens: Proibido.
Excluir Mensagens: Proibido.
Votar em Enquetes: Proibido.


Powered by phpBB © 2001, 2005 phpBB Group
Traduzido por: Suporte phpBB