Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2002-11

TPrinter

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

andrew johnson
to Tony Maro: I'm considering starting work on a TPrinter object that for starters will generate…

Nope, but I got D4, and I do not think there are many differences(if any at all). This what I get According to the Help Files properties and methods:

  TPrinterOrientation = (poPortrait, poLandscape);
  TPrinterCapability = (pcCopies, pcOrientation, pcCollation);
  TPrinterCapabilities = set of TPrinterCapability;
  TPrinter = class(TObject)
  {everything is public}
  public
    procedure Abort;//aborts print
    procedure BeginDoc; //initialize printer, or PS header info and
start first page
    procedure EndDoc; //Finish Document, cleanup etc.
    procedure NewPage;//start a new page
    {I have no idea what these 2 are, or if you should care}
    procedure GetPrinter(ADevice, ADriver, APort: PChar; var
ADeviceMode: THandle);
    procedure SetPrinter(ADevice, ADriver, APort: PChar; ADeviceMode:
THandle);
    property Aborted: Boolean;//(RO) has the document been aborted via
abort function or internal error
    property Canvas: TCanvas;//(RO) canvas drawn too
    property Capabilities: TPrinterCapabilities;//(RO) what printer
supports by way of advanced features
    property Copies: Integer;//(RW) hw many copies too print
    property Fonts: TStrings;//(RO) what fonts Printer
supports(internally), probably can be ignored
    property Handle: HDC;//(RO) windows physical handle, will probably
be usefull if Printing is ever added to the interface backend, but other
wise probably ignore
    { these are the obvious page properties }
    property Orientation: TPrinterOrientation;//(RW)
    property PageHeight: Integer;//(RO)
    property PageWidth: Integer;//(RO)
    property PageNumber: Integer;(RO)
    property PrinterIndex: Integer;//(RW) current page being written too
    property Printing: Boolean;//(RO) is it currently printing, aka has
BeginDoc been called
    property Printers: TStrings;//(RO) what printers are available in
the system, I do not know why this is part of the component and not its
own routine
    property Title: string;//(RW) Title Windows refers to Print Job as
  end;

AFAIK these are the only other(important) things in D4 Printer.pas :

function Printer: TPrinter;//get the currently assigned printer
function SetPrinter(NewPrinter: TPrinter): TPrinter;//Change current
printer

procedure AssignPrn(var F: Text);//assign a file to the current printer so that whatever is written to the file is written to the printer(CR/Writeln at the end of the Document will autmatically call newpage)

hope this helps! But as you can see Delphi(or win32) doesn't provide any nice way of handling the setting of the printer, so you can add properties and so forth without too much worry of compatibility.

Andrew

Tony Maro wrote 5 lines
I'm considering starting work on a TPrinter object that for starters will generate postscript output. Does anyone have a D5 or later object definition for a TPrinter that I could look at for compatibility reasons?

Reply by email

Nikolai Zhubr
to Tony Maro: I'm considering starting work on a TPrinter object that for starters will generate…

Hi

Tony Maro wrote 5 lines
I'm considering starting work on a TPrinter object that for starters will generate postscript output. Does anyone have a D5 or later object definition for a TPrinter that I could look at for compatibility reasons?

Attached is Delphi 6 one.

Best regards, Nikolai Zhubr > Thanks, ------------------ Get free mailbox 20 Mb at http://www.hotbox.ru type EPrinter = class(Exception); { TPrinter } { The printer object encapsulates the printer interface of Windows. A print job is started whenever any redering is done either through a Text variable or the printers canvas. This job will stay open until EndDoc is called or the Text variable is closed. The title displayed in the Print Manager (and on network header pages) is determined by the Title property. EndDoc - Terminates the print job (and closes the currently open Text). The print job will being printing on the printer after a call to EndDoc. NewPage - Starts a new page and increments the PageNumber property. The pen position of the Canvas is put back at (0, 0). Canvas - Represents the surface of the currently printing page. Note that some printer do not support drawing pictures and the Draw, StretchDraw, and CopyRect methods might fail. Fonts - The list of fonts supported by the printer. Note that TrueType fonts appear in this list even if the font is not supported natively on the printer since GDI can render them accurately for the printer. PageHeight - The height, in pixels, of the page. PageWidth - The width, in pixels, of the page. PageNumber - The current page number being printed. This is incremented when ever the NewPage method is called. (Note: This property can also be incremented when a Text variable is written, a CR is encounted on the last line of the page). PrinterIndex - Specifies which printer in the TPrinters list that is currently selected for printing. Setting this property to -1 will cause the default printer to be selected. If this value is changed EndDoc is called automatically. Printers - A list of the printers installed in Windows. Title - The title used by Windows in the Print Manager and for network title pages. } TPrinterState = (psNoHandle, psHandleIC, psHandleDC); TPrinterOrientation = (poPortrait, poLandscape); TPrinterCapability = (pcCopies, pcOrientation, pcCollation); TPrinterCapabilities = set of TPrinterCapability; TPrinter = class(TObject) private FCanvas: TCanvas; FFonts: TStrings; FPageNumber: Integer; FPrinters: TStrings; FPrinterIndex: Integer; FTitle: string; FPrinting: Boolean; FAborted: Boolean; FCapabilities: TPrinterCapabilities; State: TPrinterState; DC: HDC; DevMode: PDeviceMode; DeviceMode: THandle; FPrinterHandle: THandle; procedure SetState(Value: TPrinterState); function GetCanvas: TCanvas; function GetNumCopies: Integer; function GetFonts: TStrings; function GetHandle: HDC; function GetOrientation: TPrinterOrientation; function GetPageHeight: Integer; function GetPageWidth: Integer; function GetPrinterIndex: Integer; procedure SetPrinterCapabilities(Value: Integer); procedure SetPrinterIndex(Value: Integer); function GetPrinters: TStrings; procedure SetNumCopies(Value: Integer); procedure SetOrientation(Value: TPrinterOrientation); procedure SetToDefaultPrinter; procedure CheckPrinting(Value: Boolean); procedure FreePrinters; procedure FreeFonts; public constructor Create; destructor Destroy; override; procedure Abort; procedure BeginDoc; procedure EndDoc; procedure NewPage; procedure GetPrinter(ADevice, ADriver, APort: PChar; var ADeviceMode: THandle); procedure SetPrinter(ADevice, ADriver, APort: PChar; ADeviceMode: THandle); procedure Refresh; property Aborted: Boolean read FAborted; property Canvas: TCanvas read GetCanvas; property Capabilities: TPrinterCapabilities read FCapabilities; property Copies: Integer read GetNumCopies write SetNumCopies; property Fonts: TStrings read GetFonts; property Handle: HDC read GetHandle; property Orientation: TPrinterOrientation read GetOrientation write SetOrientation; property PageHeight: Integer read GetPageHeight; property PageWidth: Integer read GetPageWidth; property PageNumber: Integer read FPageNumber; property PrinterIndex: Integer read GetPrinterIndex write SetPrinterIndex; property Printing: Boolean read FPrinting; property Printers: TStrings read GetPrinters; property Title: string read FTitle write FTitle; end; { Printer function - Replaces the Printer global variable of previous versions, to improve smart linking (reduce exe size by 2.5k in projects that don't use the printer). Code which assigned to the Printer global variable must call SetPrinter instead. SetPrinter returns current printer object and makes the new printer object the current printer. It is the caller's responsibility to free the old printer, if appropriate. (This allows toggling between different printer objects without destroying configuration settings.) } function Printer: TPrinter; function SetPrinter(NewPrinter: TPrinter): TPrinter; { AssignPrn - Assigns a Text variable to the currently selected printer. Any Write or Writeln's going to that file variable will be written on the printer using the Canvas property's font. A new page is automatically started if a CR is encountered on (or a Writeln is written to) the last line on the page. Closing the text file will imply a call to the Printer.EndDoc method. Note: only one Text variable can be open on the printer at a time. Opening a second will cause an exception.} procedure AssignPrn(var F: Text); implementation

Reply by email

Tony Maro

I'm considering starting work on a TPrinter object that for starters will generate postscript output.

Does anyone have a D5 or later object definition for a TPrinter that I could look at for compatibility reasons?

Thanks,

Reply by email