Autor Beitrag
FSS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83

Win 7 Professional 64Bit
Delphi 7 PE, Delphi 2005 PE, Turbo Delphi Explorer 2006
BeitragVerfasst: Di 17.10.06 19:02 
Hallo,

ich arbeite gerade an einem kleinen Spiel. Der Benutzer kann per Mausklick beliebig viele TImages erstellen.
Nun möchte ich, dass alle diese Images gelöscht werden.

Weiß jemand wie ich das bewerkstelligen könnte?
binco
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Di 17.10.06 19:11 
Hilfreich wäre der Quelltext...
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 17.10.06 19:15 
Am einfachsten wäre es wahrscheinlich, die erstellten Images in eine TObjectlist oder ein Array auf TImage zu packen, und dann die Elemente in der Liste/Array per .free zu löschen.

_________________
We are, we were and will not be.
FSS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83

Win 7 Professional 64Bit
Delphi 7 PE, Delphi 2005 PE, Turbo Delphi Explorer 2006
BeitragVerfasst: Di 17.10.06 19:19 
Hier ist mal der Quelltext:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
procedure TForm1.MouseDown(Sender: TObject; Button: TMouseButton;      //beim klick auf das Formular wird die Mausposition in zwei Variablen vom Typ Integer geschrieben 
  Shift: TShiftState; X, Y: Integer);
begin
  mx := x + 5;
  my := y + 5;
end;

procedure TForm1.FormClick(Sender: TObject);   //und die Images werden erstellt
begin
 with TImage.Create(Self) do begin
    Parent := self; // !!!!!!!!
    pic := pic + 1 ;                           //pic ist ein Integer und zählt, wie viele Images erstellt werden
    Name := 'Image' + IntToStr(pic);
    Top := my;
    Left := mx;
    Width := 21;
    Height := 20;
    Picture.LoadFromFile(ExtractFilePath(Application.ExeName) + 'Data\bild.bmp');
    TransparentColor := True;
    Transparent := True;
  end;

end;
TuringTracer
Hält's aus hier
Beiträge: 12



BeitragVerfasst: Mi 18.10.06 14:48 
Moin!

Hab einfach mal den ersten Gedanken von user profile iconGausi genommen und grob in Source gewandelt (glaub ich zumindest...)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
var
  Form1: TForm1;
  mx,my,pic: Integer;
  list: TObjectList;

procedure TForm1.FormClick(Sender: TObject);
var img: TImage;
begin
 Inc(pic);
 img := TImage.Create(self);
 with img do begin
  ... // do all the stuff
 end;
 list.Add(img);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 list.Clear;
 pic := 0;
end;


Ach ja : ein
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.FormCreate(Sender: TObject);
begin
 pic := 0;
 list := TObjectList.Create();
end;
o.ä. versteht sich wohl von selbst...

Ach ja #2 : ...und vergiss nicht das
ausblenden Delphi-Quelltext
1:
uses ..., Contnrs;					
für die TObjectList...

Grüße
FSS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83

Win 7 Professional 64Bit
Delphi 7 PE, Delphi 2005 PE, Turbo Delphi Explorer 2006
BeitragVerfasst: Mi 18.10.06 19:38 
Danke TuringTracer, ich werde das morgen (war heute schon den den ganzen Tag unterwegs) testen.
FSS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83

Win 7 Professional 64Bit
Delphi 7 PE, Delphi 2005 PE, Turbo Delphi Explorer 2006
BeitragVerfasst: Do 19.10.06 14:05 
Ok, habs ausprobiert und es funktioniert einwandfrei!

Vielen, vielen Dank!
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Do 19.10.06 16:28 
Die Variable pic brauchst du dann eigentlich auch nicht mehr. Mit list.count hast du die Anzahl an Bildern. ;-)

_________________
Ein Nutzer der Ecke ;-)
FSS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83

Win 7 Professional 64Bit
Delphi 7 PE, Delphi 2005 PE, Turbo Delphi Explorer 2006
BeitragVerfasst: Do 19.10.06 20:27 
Yes :)