Bonjour à tous

j'essaie ce bout de code pour imprimer sous Windows, mais j'ai toujours un message d'erreur d'impression.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
unit Unit1;
 
{$mode objfpc}{$H+}
 
interface
 
uses
  Classes, SysUtils, FileUtil, PrintersDlgs, Forms, Controls, Graphics, Dialogs,
  StdCtrls, Printers;
 
type
 
  { TForm1 }
 
  TForm1 = class(TForm)
    Imprimer: TButton;
    PrinterSetupDialog1: TPrinterSetupDialog;
    procedure ImprimerClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.lfm}
 
{ TForm1 }
 
 
  procedure TForm1.ImprimerClick(Sender: TObject);
  begin
    Printer.BeginDoc;
 
    with Printer.Canvas do
    begin
      CopyMode:= cmSrcCopy;
      CopyRect(Rect(30, 30, 600, 600), GetFormImage.Canvas, Rect(0, 0, Width, Height));
      Brush.Style:= bsClear;
      Pen.Width:= 3;
      Rectangle(0, 0, 200, 50);    {Tracé d'un rectangle}
    end;
    printer.EndDoc;
  end;
 
 
 
end.
J'ai bien printers dans les uses et printer4lazarus dans les paquets requis.