Criar componente em tempo de execução

Delphi

14/12/2010

Gostaria de saber se alguém já criou ou saberia me dizer como criar um TCategoryPanel em tempo de execução?

Estou precisando fazer da seguinte forma:

Um formulário com 2 Panel e um Button

no evento Click do botão já tem o seguinte código, onde crio o TCategoryPanelGroup:

procedure TForm1.btnCriarClick(Sender: TObject);var  LCategoryPanelGroup: TCategoryPanelGroup;  LCategoryPanel: TCategoryPanel;  I, J: Integer; begin  LCategoryPanelGroup := TCategoryPanelGroup.Create(Form1);  LCategoryPanelGroup.Parent := Panel1;  LCategoryPanelGroup.Align := alClient;  LCategoryPanelGroup.Name := 'CategoryPanelGroup';  for I := 0 to 2 do  begin    // essa parte do código não funciona    LCategoryPanel: TCategoryPanel.Create(Form1);    LCategoryPanel.SetParent(LCategoryPanelGroup);     LCategoryPanel.Width := 198;    LCategoryPanel.Height := 200;    LCategoryPanel.Top := I * 200;    LCategoryPanel.Name := 'CategoryPanel'+IntToStr(I);    LCategoryPanel.Caption := 'Caption '+IntToStr(I);    for I := 0 to 2 do     begin      // criação de edits dentro do CategoryPanel      // ...    end;  end;end;
Daniel Gomes..

Daniel Gomes..

Curtidas 0

Respostas

Wesley Yamazack

Wesley Yamazack

14/12/2010

Olá Daniel, olhando seu chamado consegui fazer o seguinte :


procedure TForm2.Button1Click(Sender: TObject);
var
  LCategoryPanelGroup: TCategoryPanelGroup;
  LCategoryPanel: TCategoryPanel;
  LEdit : TEdit;
  I, J , K: Integer;

begin

  LCategoryPanelGroup := TCategoryPanelGroup.Create(Form2);
  LCategoryPanelGroup.Align := alClient;
  LCategoryPanelGroup.Name := 'CategoryPanelGroup';
  LCategoryPanelGroup.Parent := Panel1;
  K :=  0;
  for I := 1 to 3 do
  begin
    // essa parte do código não funciona
    LCategoryPanel         := TCategoryPanel.Create(Form2);
    LCategoryPanel.Width   := 198;
    LCategoryPanel.Height  := 200;
    LCategoryPanel.Top     := I * 200;
    LCategoryPanel.Name    := 'CategoryPanel'+IntToStr(I);
    LCategoryPanel.Caption := 'Caption '+IntToStr(I);
    LCategoryPanel.Parent  := LCategoryPanelGroup;
    for J := 1 to 2 do
    begin
      // criação de edits dentro do CategoryPanel
      LEdit         := TEdit.Create(Form2);
      LEdit.Width   := 70;
      LEdit.Height  := 20;
      LEdit.Top     := J * 30;
      Inc(K);
      LEdit.Name    := 'LEdit'+IntToStr(K);
      LEdit.Text    := 'Text '+IntToStr(K);
      LEdit.Parent  := LCategoryPanel;
    end;
    Inc(K);
  end;
end;



Não sei se é exatamente isso que você quer, mas fiz aqui umas adaptações, e esta funcionando, da uma olhada. Se não for isso explica melhor para poder te ajudar.

Um abraço

Wesley Y
GOSTEI 0
POSTAR