The MetaFile doesn't update itself until you free the MetaFileCanvas. (The code you posted actually shows that, but the call to Free
has been commented out.)
Embarcadero's example is wrong in another sense, too. All painting to the form should be done in the OnPaint
event, not from anywhere else. (I blame that on much of the documentation sample code having been contributed by users, and it's only reviewed by the documentation team and not the development team, AFAICT.)
procedure TForm1.FormPaint(Sender: TObject);
var
MetaFile: TMetafile;
MFCanvas: TMetafileCanvas;
begin
MetaFile := TMetafile.Create;
try
MetaFile.SetSize(200, 200);
try
MFCanvas := TMetafileCanvas.Create(MetaFile, Canvas.Handle);
MFCanvas.Brush.Color := clRed;
MFCanvas.FloodFill(0, 0, clRed, fsBorder);
MFCanvas.Rectangle(10, 10, 190, 190);
finally
MFCanvas.Free;
end;
Self.Canvas.StretchDraw(Rect(0, 0, 200, 200), MetaFile);
finally
MetaFile.Free;
end;
end;