Recent

Author Topic: Errors - Print-Form.  (Read 4359 times)

seghele0

  • Full Member
  • ***
  • Posts: 173
Errors - Print-Form.
« on: December 20, 2021, 03:43:12 pm »
Found the code on Google for printing the Form.
Can someone help me to resolve the errors?
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5.   Windows, Classes, SysUtils, Forms, Controls, Graphics,
  6.   Dialogs, ExtCtrls, Buttons, Printers;
  7. type
  8.   { TForm1 }
  9.   TForm1 = class(TForm)
  10.     Panel1: TPanel;
  11.     SpeedButton1: TSpeedButton;
  12.     procedure SpeedButton1Click(Sender: TObject);
  13.   private
  14.   public
  15.   end;
  16. var
  17.   Form1: TForm1;
  18. implementation
  19. {$R *.lfm}
  20. { TForm1 }
  21. procedure TForm1.SpeedButton1Click(Sender: TObject);
  22. var MyPrinter : TPrinter;
  23.       myBitMap : TBitMap;
  24. begin
  25.   myBitMap := TBitMap.Create;
  26.   myBitMap.Height := form1.Height;
  27.   form1.BorderStyle:=bsNone;
  28.   form1.PaintTo(myBitMap.Canvas, 0, 0);
  29.   form1.BorderStyle:=bsSingle;
  30.   MyPrinter := Printer;
  31.   MyPrinter.BeginDoc;
  32.   myPrinter.Canvas.CopyRect(Classes.Rect(0, 0,
  33.           RoundToInt(myPrinter.PaperSize.Width/2),
  34.           RoundToInt(myPrinter.PaperSize.Height/2)),
  35.           myBitMap.Canvas, Classes.Rect(0, 0, myBitMap.Width,
  36.           myBitMap.Height));
  37.   MyPrinter.EndDoc;
  38.   myBitMap.Free;
  39. end;
  40. end.                        

The errors:
Code: Pascal  [Select][+][-]
  1. Compile Project, Target: project1.exe: Exit code 1, Errors: 2
  2. unit1.pas(46,11) Error: Identifier not found "RoundToInt"
  3. unit1.pas(47,11) Error: Identifier not found "RoundToInt"
  4.  

VisualLab

  • Sr. Member
  • ****
  • Posts: 321
Re: Errors - Print-Form.
« Reply #1 on: December 20, 2021, 04:12:32 pm »
"Round" instead "RoundToInt".

seghele0

  • Full Member
  • ***
  • Posts: 173
Re: Errors - Print-Form.
« Reply #2 on: December 20, 2021, 04:49:29 pm »
Thank you for the info.
Compiling is OK, but still ERROR after running the program.
 :(



winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Errors - Print-Form.
« Reply #3 on: December 20, 2021, 04:56:19 pm »
Hi!

The Lazarus printing trap:

The compiler does not complain, but you need  the unit

Printer4Lazarus

for printing.

PS.: Fastet gun in the west: Jamie

Winni


seghele0

  • Full Member
  • ***
  • Posts: 173
Re: Errors - Print-Form.
« Reply #4 on: December 20, 2021, 05:55:51 pm »
I've add Printer4Lazarus in the Project inspector.
Compiling is still OK.
After "run", the printer works, but only a blank page.
???

VisualLab

  • Sr. Member
  • ****
  • Posts: 321
Re: Errors - Print-Form.
« Reply #5 on: December 20, 2021, 05:59:54 pm »
The code is missing an instruction to specify the width of the printed bitmap. Add:

Code: Pascal  [Select][+][-]
  1. LMyBitmap.Width := Form1.Width;
  2.  

seghele0

  • Full Member
  • ***
  • Posts: 173
Re: Errors - Print-Form.
« Reply #6 on: December 20, 2021, 06:07:58 pm »
THANK YOU.
 :)


 

TinyPortal © 2005-2018