Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Crear dinámicamente componentes en el formulario (https://www.clubdelphi.com/foros/showthread.php?t=27656)

D@byt 27-11-2005 22:01:18

Crear dinámicamente componentes en el formulario
 
¿Cómo puedo crear componentes dinámicos en el formulario?. Ejemplo: A partir de un componenete quiero crear 30 iguales, luego utilizarlos y finalmente destruirlos. Muchas gracias.

marcoszorrilla 27-11-2005 22:20:18

A ver si este ejemplo te sirve:
Código Delphi [-]
 unit crearbotones;
 
 interface
 
 uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
   StdCtrls;
 
 type
   TfrCrearbotones = class(TForm)
     Button1: TButton;
     procedure Button1Click(Sender: TObject);
     procedure cerrar(Sender:Tobject);
     procedure FormClose(Sender: TObject; var Action: TCloseAction);
     procedure FormCreate(Sender: TObject);
   private
     { Private declarations }
   public
     { Public declarations }
   end;
 
 var
   frCrearbotones: TfrCrearbotones;
 
 implementation
 
 {$R *.DFM}
 
 procedure TfrCrearbotones.Button1Click(Sender: TObject);
 var
 boton:TButton;
 i:integer;
 ancho:Integer;
 centro:Integer;
 
 begin
 ancho:=Screen.Width;
 ancho:=ancho - 100;
 centro:=ancho div 2 ;
         for i:=0 to 17 do
         begin
         //botones izquierda
         boton:=TButton.Create(frCrearbotones);
         boton.name:='boton'+intToStr(i);
         boton.Parent:=frCrearBotones;
         boton.SetBounds(1+i*8,1+i*22,100,20);
         boton.Caption:='Mi botón'+intToStr(i);
         boton.OnClick :=cerrar;
         //botones centro
         boton:=TButton.Create(frCrearBotones);
         boton.name:='boton'+intToStr(i+36);
         boton.Parent:=frCrearBotones;
         boton.SetBounds(centro,1+i*22,100,20);
         boton.Caption:='Mi botón'+intToStr(i+36);
         boton.OnClick :=cerrar;
         //botones derecha
         boton:=TButton.Create(frCrearBotones);
         boton.name:='boton'+intToStr(i+18);
         boton.Parent:=frCrearBotones;
         boton.SetBounds(ancho-i*8,1+i*22,100,20);
         boton.Caption:='Mi botón'+intToStr(i+18);
         boton.OnClick :=cerrar;
 
 
         end;
         button1.caption:='Cerrar';
         button1.onclick:=Cerrar;
 end;
 
 procedure TfrCrearbotones.cerrar(Sender:Tobject);
 begin
 close;
 end;
 
 
 procedure TfrCrearbotones.FormClose(Sender: TObject; var Action: TCloseAction);
 begin
 Action:=CaFree;
 end;

Un Saludo.

dec 27-11-2005 22:30:05

Hola,

Como apoyo a lo que Marcos te propone, acaso no esté demás que eches un vistazo a este Hilo publicado hace unos días solamente. Una búsqueda "manual" en el apartado OOP de los Foro podría también ayudarte, y, probablemente, también te ayude realizar una búsqueda en los Foros.


La franja horaria es GMT +2. Ahora son las 02:40:49.

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