TsgDWGImage in reports
Posted: 26 Jul 2005, 00:41
I'm trying to add CADImportVCL support to my Report Builder reports. There is a TppImage in report builder - but assigning a TsgDWGImage to it doesn't work well: the image is only a few dozen pixels high and wide...
I tried assigning to metafile first, then assigning the metafile to the TppImage, and that works well - except that there is a memory leak (I think because the reference count on EnhMetafile is never decremented properly).
I created a simple project with just a TImage and a TButton - same memory leak (palette not released, TEnhMetafile still allocated) - tested with MemProof and Memory Sleuth.
Here's the relevant code:
Can someone suggest an alternate way for me to get data transferred to TppImage? (It is based on TPicture, with wrapper methods to control how it is displayed on screen).
I'm looking for a way to either assign the metafile and destroy it without resource leaks, or perhaps to calculate a Width and Height that can be sent to ppImage so it renders properly.
Cheers,
EdB
I tried assigning to metafile first, then assigning the metafile to the TppImage, and that works well - except that there is a memory leak (I think because the reference count on EnhMetafile is never decremented properly).
I created a simple project with just a TImage and a TButton - same memory leak (palette not released, TEnhMetafile still allocated) - tested with MemProof and Memory Sleuth.
Here's the relevant code:
Code: Select all
(button1 click)
<b>var</b>
vDWG : TsgDWGImage;
fName : string;
mf : TMetafile;
<b>begin</b>
// image1.Picture.Bitmap.ReleaseHandle;
fName:='d:\projects\images\GMX0247P.dwg';
mf:=tmetafile.create;
mf.ReleaseHandle;
<b>try</b>
vDWG := TsgDWGImage.Create;
<b>try</b>
vDWG.LoadFromFile(fName);
vDWG.IsWithoutBorder:=True;
vDWG.BackgroundColor:=clWhite;
vDWG.UseWinEllipse:=True;
vDWG.GetExtents;
{.$DEFINE ASSIGNTOIMAGE} // define to test direct to image - no resource leaks
{$IFDEF ASSIGNTOIMAGE}
image1.Picture.Assign(vDWG);
Exit;
{$ELSE}
mf.Assign(vdwg.ExportToMetafile(3276700));
{.$DEFINE TESTRB} // define to test with report builder
{$IFDEF TESTRB}
ppImage1.Picture.Assign(mf);
ppReport1.Print;
{$ELSE}
image1.picture.Assign(mf);
{$ENDIF}
{$ENDIF}
<b>finally</b>
vDWG.Free;
vDWG:=nil;
<b>end</b>;
<b>finally</b>
// DeleteObject(mf.Palette); // this fixes palette problem
// DeleteEnhMetaFile(mf.Handle);
mf.Free;
mf := <b>nil</b>;
<b>end</b>;
<b>end</b>;
I'm looking for a way to either assign the metafile and destroy it without resource leaks, or perhaps to calculate a Width and Height that can be sent to ppImage so it renders properly.
Cheers,
EdB