Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/VCL/Graphics    [ Add a report in this area ]  
Report #:  94085   Status: Reported
Allow metafile to support successive creation of canvas without loosing image
Project:  Delphi Build #:  14.0.3593.25826
Version:    14.2 Submitted By:   David Tetard
Report Type:  Suggestion / Enhancement Request Date Reported:  5/21/2011 3:54:14 AM
Severity:    Infrequently encountered problem Last Updated: 5/22/2011 5:25:16 PM
Platform:    All platforms Internal Tracking #:  
Resolution: None  Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
Hi,

I'd like to be able to draw on a metafile using a succession of TMetafileCanvas without loosing previous drawing.
This is best explained using the code example below:

procedure TForm6.Image1Click(Sender: TObject);
Var
   MF : TMetafile;
   MFC : TMetafileCanvas;
begin
     MF := TMetafile.Create;
     Try
          MF.SetSize(250, 250);

          // First drawing using first canvas:
          MFC := TMetafileCanvas.Create(MF, 0);
          Try
               MFC.TextOut(10, 10, 'xxxx');
          Finally
               MFC.Free;
          End;

          // Second drawing using second canvas:
          MFC := TMetafileCanvas.Create(MF, 0);
          Try
               MFC.TextOut(50, 50, 'yyyy');
          Finally
               MFC.Free;
          End;

          Image1.Picture.Assign(MF);
     Finally
          MF.Free;
     End;
end;


In this case, the creation fo the second canvas erases the previous drawing and you only get the drawn "yyyy" text. What I'd like is to be able to do this and have both drawing on the resulting MF.

NB: Of course, this example is not useful in itself (you could draw both texts using the same canvas) but in cases of a metafile that's a composite of several complex drawings done by several methods, it's good to be able to pass only a TMetafile and have each routine create its own canvas and draw on the metafile rather than have to pass both metafile and canvas as parameters, as in:

Requested solution:

Procedure DrawBackground(MF : TMetafile);
begin
...
end;

procedure DrawXAxis(MF : TMetafile);
begin
...
end;

...

procedure DrawGraph;
var
    MF : TMetafile;
begin
     MF := TMetafile.Create;
     Try
          MF.SetSize(...);
         DrawBackground(MF);
         DrawXAxis(MF);
         ...
    Finally
         MF.Free;
    End;
End;


Currently, the only option is the following that's more cumbersome in some cases:

Procedure DrawBackground(MF : TMetafile; MFC : TMetafileCanvas);
begin
...
end;

procedure DrawXAxis(MF : TMetafile; MFC : TMetafileCanvas);
begin
...
end;

...

procedure DrawGraph;
var
    MF : TMetafile;
MFC : TMetafileCanvas;
begin
     MF := TMetafile.Create;
     Try
          MF.SetSize(...);
         MFC := TMetafileCanvas.Create(MF, 0);
         Try
              DrawBackground(MF, MFC);
              DrawXAxis(MF, MFC);
              ...
         Finally
              MFC.Free;
          End;
    Finally
         MF.Free;
    End;
End;
Steps to Reproduce:
1- Create VCL form
2- Add TImage on it.
3- In OnClick of image, copy code in description.

Run app, click image, and observe the image. No xxx text displayed, meaning that the second canvas erased the work of the first one.

Workarounds
None
Attachment
None
Comments

None

Server Response from: ETNACODE01