以下是TPicture的部分实现,看了看,Assign(nil)并无不妥吧。
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; //DBImage的Picture占用的内存在这里释放
FGraphic := NewGraphic; //这里NewGraphic是nil
Changed(Self);
except
NewGraphic.Free;
raise;
end;
end;
还请sunziqi指教。