image1.Picture:=nil;
虽然已经NILl了..可是下面怎么测都是not nil ???
if image1.Picture=nil then
showmessage('image1 picture is nil')
else showmessage('image1 picture is not nil');
查VCL,可以看到
procedure TImage.SetPicture(Value: TPicture);
begin
FPicture.Assign(Value);
end;
procedure TPicture.Assign(Source: TPersistent);
begin
if Source = nil then
SetGraphic(nil)
else if Source is TPicture then
SetGraphic(TPicture(Source).Graphic)
else if Source is TGraphic then
SetGraphic(TGraphic(Source))
else
inherited Assign(Source);
end;
procedure TPicture.SetGraphic(Value: TGraphic);
var
NewGraphic: TGraphic;
begin
NewGraphic := nil;
if Value <> nil then
begin
NewGraphic := TGraphicClass(Value.ClassType).Create;
NewGraphic.Assign(Value);
NewGraphic.OnChange := Changed;
NewGraphic.OnProgress := Progress;
end;
try
FGraphic.Free; //<------ 此处释放了原来的图像
FGraphic := NewGraphic; //<--------- 使用新图像
Changed(Self);
except
NewGraphic.Free;
raise;
end;
end;