Recent

Author Topic: Printer control  (Read 2891 times)

Jayndel

  • Newbie
  • Posts: 5
Printer control
« on: July 25, 2018, 09:17:25 am »
what is the alternative to  Delphi commands

"Prn := TPrintObject.Create;"
and
"GetTextMetrics( Printer.Canvas.Handle,TextMetrics );"

Any help greatly appreciated.


dbannon

  • Hero Member
  • *****
  • Posts: 2796
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Printer control
« Reply #1 on: July 25, 2018, 12:16:54 pm »
"any help" ?

Not answering your question but ...

use the  'Printers" unit. It declares a thing called Printer. You can then -

printer.begindoc
...
Printer.Canvas.TextOut(XOffset, YOffset, 'something');
printer.canvas.Line(LeftEdge, CurrentY, RightEdge, CurrentY);
....
Printer.EndDoc;

for an example, see https://github.com/tomboy-notes/tomboy-ng/blob/master/tomboy-ng/k_prn.pas

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Printer control
« Reply #2 on: July 25, 2018, 01:55:11 pm »
what is the alternative to  Delphi commands

"Prn := TPrintObject.Create;"
and
"GetTextMetrics( Printer.Canvas.Handle,TextMetrics );"

Any help greatly appreciated.
That object is not a standard Delphi object, afaik, but third party code it seems.
The printers - as suggest above - unit is 100% Delphi compatible.

The second question works out of the box on windows systems only: it is a windows API call.
(And to be sure: DON'T use mode objfpc but mode delphi, although that is probably not related.)

Also note that PRN is directly avalable when you use the printer unit instead or the printers unit.
The difference is the line printer device vs the printer.canvas.
« Last Edit: July 25, 2018, 02:32:32 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Printer control
« Reply #3 on: July 25, 2018, 02:47:33 pm »
Printer.Canvas has a
Code: Pascal  [Select][+][-]
  1. GetTextMetrics(out TM: TLCLTextMetric): boolean;
function

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Printer control
« Reply #4 on: July 25, 2018, 03:09:59 pm »
Printer.Canvas has a
Code: Pascal  [Select][+][-]
  1. GetTextMetrics(out TM: TLCLTextMetric): boolean;
function
Tnx Howard, forgot about that one. And it is cross-platform too.
OP uses the Windows API call, though.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Jayndel

  • Newbie
  • Posts: 5
Re: Printer control
« Reply #5 on: July 26, 2018, 09:14:58 am »
Thanks All.
This is exactly what I have been looking for.
Haven't coded for around 12 years & a tad rusty.
Stay well.

 

TinyPortal © 2005-2018