Welcome, Guest
Username: Password: Remember me
CodeTyphon MS Windows (Win7, Win8.x, Win10 and Win11) OS Development, discussions and problems
  • Page:
  • 1

TOPIC:

Printing 4 years 7 months ago #14629

  • Leo Seghers
  • Leo Seghers's Avatar Topic Author
  • Visitor
  • Visitor
Hello,
I’m no programmer, so my knowledge about programming is very poor.
When using CT 5.5 I had no problem of printing the following procedure.
Now, I installed CT 7.1 and the printer stays on hold.
There are no errors when compiling en building the program.
The main question is simple, I just want to print a form.
Could you please help me?
//***
Uses
 LCLIntf, LCLType, LCLProc,
 LR_Class, LResources,
 Windows, SysUtils, Classes, Clipbrd,StdCtrls,
 Controls, Forms, Dialogs, ExtCtrls,
 Buttons, Menus,
 sqlite3dyn, sqlite3conn, sqldb, db, DbCtrls, DBGrids,
 DateUtils, FileUtil,
 Variants, Printers, OSPrinters, RTTICtrls,
 IntfGraphics, GraphType, Graphics, Types;
//***
procedure TFviewer.PrintForm(centredOnPage: boolean; anOrientation: TPrinterOrientation);
var
   VARmyBitMap: TBitMap;
   VARprnBmp: TBitmap;
   VARprnRct: TRect;
   VARHScaleFactor: Single;
   VARVScaleFactor: Single;
   VARaLeft: Integer;
   VARaTop: Integer;
   VARaSize: TSize;
begin
Try
  VARHScaleFactor:=Printer.XDPI/Screen.PixelsPerInch;
  VARVScaleFactor:=Printer.YDPI/Screen.PixelsPerInch;
  VARmyBitMap:= TBitMap.Create;
  VARprnBmp:=TBitmap.Create;
  try
    Printer.Orientation:=anOrientation;
    VARmyBitMap.LoadFromDevice(Canvas.Handle);
    VARprnBmp.SetSize(trunc(VARmyBitMap.Width*VARHScaleFactor),
                   trunc(VARmyBitMap.Height*VARVScaleFactor));
    VARprnRct:=Rect(0, 0, VARprnBmp.Width, VARprnBmp.Height);
    VARprnBmp.Canvas.StretchDraw(VARprnRct, VARmyBitMap);
    if centredOnPage then
    begin
       VARaSize:=Size(Printer.PaperSize.PaperRect.WorkRect);
       case Printer.Orientation of
         poPortrait: begin
                       VARaLeft:=(VARaSize.cx - VARprnBmp.Width) div 2;
                       VARaTop:=(VARaSize.cy - VARprnBmp.Height) div 2;
                     end;
         poLandscape: begin
                        VARaTop:=(VARaSize.cy - VARprnBmp.Height) div 2;
                        VARaLeft:=(VARaSize.cx - VARprnBmp.Width) div 2;
                      end;
       end;
    end
    else
    begin
      VARaLeft:=0;
      VARaTop:=0;
    end;
    Printer.BeginDoc;
    try
      Printer.Canvas.Draw(VARaLeft, VARaTop, VARprnBmp);
    finally
      Printer.EndDoc;
    end;
  finally
    VARmyBitMap.Free;
    VARprnBmp.Free;
  end;
except On E: Exception do
  Begin
    QuestionDlg('Error', ' ! ! ! '+#13+
    '' +#13+ '' +#13+#13+ 'ERROR: '+ E.Message, mtError, [mrOk, 'DRUK HIER  <--- '], '');
  end;
end;
end;
//***
procedure TFviewer.BitBtnPRINTClick(Sender: TObject);
begin
     PanelbtnVIEWER.Visible:=False;
     Screen.cursor := crHourGlass;
     Application.ProcessMessages;
     Sleep(1000);
     PrintForm(True, poPortrait);
     //PrintForm(True, poLandscape);
     Screen.Cursor := crDefault;
     Application.ProcessMessages;
     PanelbtnVIEWER.Visible:=True;
end;
//***

Please Log in or Create an account to join the conversation.

Printing 4 years 7 months ago #14630

  • Matis A.
  • Matis A.'s Avatar
  • Away
  • Moderator
  • Moderator
  • Posts: 1120
  • Thank you received: 166
Your OS ?
PilotLogic Core Programmer

Please Log in or Create an account to join the conversation.

Printing 4 years 7 months ago #14635

  • Leo Seghers
  • Leo Seghers's Avatar Topic Author
  • Visitor
  • Visitor
OS = Windows 10.
With the my old 'exe', compiled with CT 5.5, the printing of the form was always succesfull.
The must be a different approach in the new CT7.1 !! ??
:unsure:

Please Log in or Create an account to join the conversation.

Printing 4 years 7 months ago #14636

  • Matis A.
  • Matis A.'s Avatar
  • Away
  • Moderator
  • Moderator
  • Posts: 1120
  • Thank you received: 166
We release CT ver 5.50 at 18-Sep-2015,
many many things changed in last 5 years ... :)

Because I can't test your full Source and
all are looks OK to me in your posted source,

please look the CodeOcean sample at:
C:\codetyphon\CodeOcean\lz_Printers\samples\dialogs\selectprinter.ctpr
PilotLogic Core Programmer

Please Log in or Create an account to join the conversation.

Last edit: by Matis A..

Printing 4 years 7 months ago #14641

  • Leo Seghers
  • Leo Seghers's Avatar Topic Author
  • Visitor
  • Visitor
Thank you for the information.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1