I have this code in a VCL Forms Application:
implementation
{$R *.dfm}
var
  MyBitmap: TBitmap;
procedure TFormMain.FormCreate(Sender: TObject);
begin
  MyBitmap := TBitmap.Create;
end;
procedure TFormMain.FormDestroy(Sender: TObject);
begin
  if Assigned(MyBitmap) then
    MyBitmap.Free;
end;
procedure TFormMain.Button1Click(Sender: TObject);
begin
  if Assigned(MyBitmap) then
    MyBitmap.Free;
end;
When I click the button the second time I get an Access violation in MyBitmap.Free; in the button's click handler. But MyBitmap shouldn't be anymore assigned after the first button click. So why the condition if Assigned(MyBitmap) then does not work on the second button click when it obviously did work on the first button click?
Delphi 10.1 Berlin Update 2
 
    