Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Image löschen ? (https://www.delphipraxis.net/122210-image-loeschen.html)

thomas2009 11. Okt 2008 10:50


Image löschen ?
 
Hallo

ich erstelle Images at runtime und möchte ich danach einige löschen
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
with TImage.Create(self) do begin
     Parent := self;
     Width := 100;
     Height := 100;
     Name:='img1';
     Picture.Bitmap.LoadFromFile('C:\test.bmp');
     Top := 0;
     Left := 0;
end;
end;


procedure TForm1.Button2Click(Sender: TObject);
var
img1: TImage;
begin
img1.free;
end;
Das Programm wird aber danach ausgeblendet !

IceBube 11. Okt 2008 11:23

Re: Image löschen ?
 
Hallo!

Machs so mal:

Delphi-Quellcode:
procedure ();
var Img : TImage;
begin
Img := (FindComponent('img1') As TImage);
Img.Free;
end;
So wird das Bild gesucht und der Variable zugeordnet, dann kannst du es einfach löschen...

Nicht getestet^

lg

SimStar001 11. Okt 2008 11:26

Re: Image löschen ?
 
Zitat:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
with TImage.Create(self) do begin
     Parent := self;
     Width := 100;
     Height := 100;
     Name:='img1';
     Picture.Bitmap.LoadFromFile('C:\test.bmp');
     Top := 0;
     Left := 0;
end;
end;


procedure TForm1.Button2Click(Sender: TObject);
var
img1: TImage;
begin
img1.free;
end;

Hallo, kann es sein dass du dein Image nicht global definiert hast (schau mal in deine Button2click function) --> var img1 : TImage;


kann sein dass es daran liegt. definier sie mal global

thomas2009 11. Okt 2008 21:37

Re: Image löschen ?
 
Zitat:

Zitat von IceBube
Hallo!
Machs so mal:
Delphi-Quellcode:
procedure ();
var Img : TImage;
begin
Img := (FindComponent('img1') As TImage);
Img.Free;
end;
lg

Es hat geklappt mit FindComponent. Danke


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:21 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz