Dynamika

0

<font color="blue"><font size="12">Witam!
Jak masowo usunac stworzone wczescniej dynamiczne komponeny?</span></span> [???]

0

Np. kazdemu dynamicznemu komponentowi ustawiaj Tag na jakąs konkretna wartość (dla każdego taka samą) a potem:

var
  I : Integer;
begin
  for I := Form1.ComponentCount - 1 downto 0 do
    if Components[I].Tag = 123 then  //zamiast 123 wpisujesz wartośc jaka ustawiałeś komponentom dynamicznym
      Components[I].Free;
0

Albo utworz je jako elementy tablicy

0

mam utworzone jako elementy tablicy array of Tbutton załóżmy i teraz chce je susnac za ponoca klikniecia w button jakis inny nie tworzony dynamicznie

0

No to w czym problem ?

for I := 0 to Length(Tablica) - 1 do
  if Tablica[I] <> nil then Tablica[I].Free;
0

Jest tylko taki problem ze to co zapodales to nie dziala :/

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  b: array of TButton;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
 i : integer;
 x,y :shortint;
begin
 SetLength(b, 20);
 for i := 0 to 20 do
 begin
  b[i] := TButton.Create(Form1);
  b[i].Parent := Form1;
  Randomize;
  b[i].Left := 100+Random(x);
  b[i].Top := 150+Random(y);
  b[i].Caption := IntToStr(((Random(x)+Random(y))*i));
 end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
 p : integer;
begin
 for p := Length(b) downto 0 do
 begin
  if b[p] <> nil then
  begin
   b[p].Free;
  end;
 end;
end;

end.
0

poczytaj o: SetLength, Randomize, Random, zmiennych lokalnych...

procedure TForm1.Button1Click(Sender: TObject);
var  i : integer;
begin
 Randomize;
 SetLength(b, 20); //b[0..19]!!!
 for i := 0 to 19 do
 begin
   b[i] := TButton.Create(Form1);
   b[i].Parent := Form1;
   b[i].Left := Random(Width);
   b[i].Top := Random(Height);
   b[i].Caption := Format('%d:%d',[b[i].Left, b[i].Top]);
 end;
end;


procedure TForm1.Button2Click(Sender: TObject);
var p : integer;
begin
 for p :=0 to Length(b)-1 do
   if b[p] <> nil then
     b[p].Destroy;
end;

1 użytkowników online, w tym zalogowanych: 0, gości: 1