![]() |
![]() |
![]() |
![]() |
![]() |
FTP | ![]() |
![]() |
CCD | ![]() |
![]() |
Buscar | ![]() |
![]() |
Trucos | ![]() |
![]() |
Trabajo | ![]() |
![]() |
Foros | ![]() |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
Herramientas | Buscar en Tema | Desplegado |
#1
|
|||
|
|||
destruir objeto creado en tiempo de ejecucuión
Hola. Este codigo lo tengo en un form que pinchando en el botón me crea todos los objetos en él incluidos. Creo ahí mismo otro boton (miboton) que quiero que al pincharlo destruya todos los objetos. Así si los vuelvo a crear no me dará error. (Este codigo lo estaba probando para incluirlo en una aplicación pero como hay que crear los objetos y luego destruirlos si no los puedo destruir no me vale) Me sería de gran ayuda si indicais como destruirlos. He probado con free pero no me lo destruye o no se utilizarlo.
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, DBTables, Grids, DBGrids, ExtCtrls, Buttons, Menus; type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; OpenDialog1: TOpenDialog; BitBtn1: TBitBtn; Image1: TImage; procedure Button1Click(Sender: TObject); procedure BitBtn1Click(Sender: TObject); private procedure Img1Click(Sender: TObject); procedure mibotonClick(Sender: TObject); { Private declarations } public gb :TPAnel; { Public declarations } end; var Form1: TForm1; bg :Tpanel; implementation procedure TForm1.Img1Click(Sender: TObject); begin showmessage('Hola'); { Aquí el código que quieras que se ejecute al hacer click } end; procedure TForm1.mibotonClick(Sender: TObject); begin { Aquí quiero que me elimine todos los objetos creados que tengo que poner} end; {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var gb:TPanel; p2:Tpanel; p3 :TPanel; lbl1:TLAbel; img1 :TImage; edt1:TEdit; miboton :Tbutton; begin //crear Tpanel gb := Tpanel.Create(Self); gb.Parent := Self; gb.Name := 'RunTimeGroupBox1'; gb.Top := 10; gb.Left := 10; gb.Height := 300; gb.Width := 300; p2 := TPanel.Create(gb); p2.Parent := gb; p2.name := 'panel2'; p2.caption := 'Lo has conseguido'; p2.Top := 1; p2.Left := 1; p2.Height := 80; p2.width := 80; // Crear tImage img1 := TImage.create(p2); img1.Parent := p2; img1.Name := 'img1'; img1.Top := 1; img1.Left := 1; img1.Height := 70; img1.Width := 70; img1.picture.loadfromfile('c:\Imagenes\Siguiente.bmp'); img1.Align := AlTop; img1.AutoSize := False; img1.Stretch := true; img1.OnClick := Img1Click; //Img1.OnContextPopup := Img1ContextPopup; //Panel dentro de panel p3 := TPanel.Create(gb); p3.Parent := gb; p3.name := 'panel3'; p3.caption := 'Panel3'; p3.Top := 1; p3.Left := 81; p3.Height := 80; p3.width := 80; // Etiqueta lbl1 := TLabel.Create(Form1); lbl1.Parent := gb; // dentro del GroupBox lbl1.Name := 'RunTimeLabel1'; lbl1.Top := 40; lbl1.Left := 40; lbl1.Width := 100; lbl1.Caption := 'Etiqueta: '; // Edit edt1 := TEdit.CReate(Form1); edt1.Parent := gb; // dentro del GroupBox edt1.Name := 'RunTimeEdit1'; edt1.Top := 40; edt1.Left := 160; edt1.Width := 100; Edt1.Text := 'Escriba aquí...'; //crear un boton miboton := Tbutton.Create(Form1); miboton.Parent := form1; miboton.Name := 'mio'; miboton.Top := 270; miboton.Left := 1; miboton.Width := 100; miboton.Height := 50; miboton.OnClick := mibotonClick; end; |
|
|
![]() |
|