Question to TsgDXFImage.DrawRect

Discuss and ask questions about CAD VCL (Delphi and C++ Builder).

Moderators: SDS, support, admin

Post Reply
Emil
Posts: 8
Joined: 22 Sep 2005, 11:31
Location: Germany
Contact:

Question to TsgDXFImage.DrawRect

Post by Emil » 28 Aug 2006, 17:38

Hello,

I would like to use

TsgDXFImage.DrawRect(DC: HDC; SourceRect: TFRect; DestRect: TRect)

to print out a rectangular region of a DWG-file. Could you give me a small example? I have tried it but I get an access violation in DXFImage.pas, procedure DrawRect at line 1954 (this comes from EurekaLog, the error tracking software I use).

Thanks

support
Posts: 3254
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 29 Aug 2006, 14:58

Hello!

Please try the following code:

Code: Select all

<b>procedure</b> TMyApp.Forum_311_ButtonClick(Sender: TObject);
<b>const</b> PO: <b>array</b>[Boolean] <b>of</b> TPrinterOrientation = (poPortrait,poLandscape);
<b>var</b>
  Img: TsgDXFImage;
  FR: TFRect;
  R: TRect;
<b>begin
  if</b> OpenDialog1.Execute <b>then</b>
    sgImage1.LoadFromFile(OpenDialog1.Filename);
  <b>if</b> sgImage1.Picture.Graphic <b>is</b> TsgDXFImage <b>then
  begin</b>
    sgImage1.Align := alClient;
    Img := TsgDXFImage(sgImage1.Picture.Graphic);
  <b>end
  else
  begin</b>
    Img := <b>nil</b>;
    Exit;
  <b>end</b>;

  <b>with</b> sgImage1.Picture <b>do</b>
    Printer.Orientation := PO[Width > Height];
  <b>if</b> PrintDialog1.Execute <b>then
  begin</b>
    FR := Img.Extents;
    Printer.BeginDoc;
    FR := MakeFRect(FR.Left + (FR.Right - FR.Left) * 0.125,
      FR.Bottom + (FR.Top - FR.Bottom)* 0.125,
      FR.Z1 + (FR.Z2 - FR.Z1) * 0.125,
      FR.Left + (FR.Right - FR.Left) * 0.875,
      FR.Bottom + (FR.Top - FR.Bottom)* 0.875,
      FR.Z1 + (FR.Z2 - FR.Z1) * 0.875);

    R := Printer.Canvas.ClipRect;

    Img.DrawRect(Printer.Canvas.Handle, FR, R);
    Printer.EndDoc;
  <b>end</b>;
Sergey.

please post questions to the forum or write to support@cadsofttools.com

Post Reply