Buscar

CRIANDO UMA LISTA DE BOTÕES EM TEMPO DE EXECUÇÃO

Código

Procedure criabotão;
var
   wl_botao:Tbutton;
   wl_left,wl_top,x,wlCont,wlnome:integer;
begin
  wl_left:=10;
  wl_top:=10;
  wlCont:=0;
  wlnome:=0;
  {Percorre os componentes existentes e verifica se é do tipo TBotaoOpc}
  {Isto para posicionar corretamente o botão em tempo de execução}
  For x:=0 to ComponentCount-1 do
  begin
      If (Components[x].ClassType = Tbutton) then
      begin
          wl_Left:=wl_Left+105;
          wlCont:=wlCont+1;
          wlnome:=wlnome+1;
          if wlCont > 5 then//se tiver mais de 5 botões ele posiciona na linha abaixo
          begin
             wl_Top  := wl_Top + 60;
             wl_Left:=10;
             wlCont := 0;
          end;
      end;
  end;
  wl_botao:= Tbutton.Create(self);
  wl_botao.visible:=true;
  wl_botao.left:= wl_left;
  wl_botao.top:=wl_top;
  wl_botao.Caption:= 'teste'+inttostr(wlnome);
  wl_botao.Name:='teste'+inttostr(wlnome);
  wl_botao.Parent:=form1;//é obrigatorio declarar o pai.
end;

ALTERAÇÕES REALIZADAS POR MARCOS CALIXTO - FUNCIONADO 100%

var
   wl_edit  :     TEdit;
   wl_label :     Tlabel;

   wl_left,wl_top,wlCont      :     Integer;
   lbleft,lbtop               :     Integer;
   num_bt   :     integer;
begin
      wl_left     :=    75;
      lbleft      :=    5;
      wl_top      :=    10;
      lbtop       :=    wl_top + 5;
      wlCont      :=    1;
      num_bt      :=    1;


  while num_bt <= 9 do
  begin
                if num_bt > 1 then
                begin
                        wl_left     := wl_left + 225;
                        lbleft      :=  wl_left - 70;
                end;

                if (wlCont > 3 ) then//se tiver mais de 5 botões ele posiciona na linha abaixo
                begin
                        wl_left     :=    75;
                        lbleft      :=    5;
                        wl_top      :=    wl_top + 30;
                        lbtop       :=    wl_top + 5;
                        wlCont      :=    1;
                end;

       inc(wlCont,1);

      wl_edit     :=    TEdit.Create(self);
      wl_label    :=    Tlabel.Create(self);

      wl_edit.visible   :=true;
      wl_label.Visible  :=    true;

      wl_edit.left      := wl_left;
      wl_label.Left     := lbleft;

      wl_edit.top       :=    wl_top;
      wl_label.Top      :=    lbtop;

      wl_edit.Hint      := 'vl_parcela'+inttostr(num_bt);
      wl_edit.ShowHint  := true;

      wl_edit.Name      :=    'vl_parcela'+inttostr(num_bt);
      wl_label.Name     :=    'Parcela'+inttostr(num_bt);
      wl_label.Caption  :=    'Parcela Nº['+inttostr(num_bt)+']';

      wl_edit.Parent    :=    PanelTesteA;//é obrigatorio declarar o pai.
      wl_label.Parent   :=    PanelTesteA;
      inc(num_bt,1);
  end;



 

Publicidade

Vote na dica




Quantidade de votos: 0 votos
Aceitação: 0%


Detalhes da dica

Categoria: Componentes
Adicionada dia: 09/11/10
Por: Marcos Naves Calixto
Visualizada: 4543 vezes

Planeta Delphi - Tudo sobre programação Delphi Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009