自动创建的image控件的图片如何清空???(100分)

H

herogyf

Unregistered / Unconfirmed
GUEST, unregistred user!
程序自动建立了一个image,怎样在窗口关闭时清空该image内的picture。
 
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
image1.Picture.CleanupInstance;
image1.Hide;
end;
不知能否满足你的要求?
 
不行啊,静态的还可以,可是要求是清空动态的image里的picture.
 
image1.picture.graphic := nil;
 
我把我的源程序贴出来:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
var
image:timage;
bitmap:tbitmap;
begin
bitmap:=tbitmap.Create;
bitmap.LoadFromFile('e:/the 8/image/back.bmp');
image:=timage.Create(self);
image.Parent:=form1;
image.Width:=250;
image.Height:=180;
image.Stretch:=true;
image.Canvas.Draw(0,0,bitmap);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
.........................
end;
end.


如何在FormClose中实现image的清空。image1.picture.graphic := nil;是不行的。
 
用以下句子就行了:
image1.Picture.Free;
image1.Hide;//此句可以没有。
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
[RED]image:timage;
bitmap:tbitmap;[/RED]

public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
[BLUE]//var
//image:timage;
//bitmap:tbitmap;[/BLUE]
begin
bitmap:=tbitmap.Create;
bitmap.LoadFromFile('e:/the 8/image/back.bmp');
image:=timage.Create(self);
image.Parent:=form1;
image.Width:=250;
image.Height:=180;
image.Stretch:=true;
image.Canvas.Draw(0,0,bitmap);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
[RED]Image.free;
Bitmap.Free;[/RED]
.........................
end;
end.

 
多人接受答案了。
 
顶部