Board index » delphi » Printing to a non default printer under NT

Printing to a non default printer under NT

Bit of a conundrum this.....

I have a system running NT4 Sp 4 & Delphi 4

I want to print to a card printer (an NBS Plastic Card Printer to be
precise) without it being the default windows
printer.

To demonstrate the problem, I wrote a small test app:

The form consists of a Combo box, two buttons and a PrintDialog tool.

Button1 is labelled 'Test Print'       Button 2 is 'Choose Via Dialog'

The combo box is filled with the available list of printers (Not sorted)

If you chose the printer using the combo box  then press 'Test Print' the
application fails

If you chose the printer using the combo box then press is 'Choose Via
Dialog',. confirm the current choice
and then Test Print the application runs fine.
Any subsequent changes using the combo box works fine in the current
execution.

I have included the form code below: any pointers would be useful....

James.

unit NBSTEST;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,Printers;

type
  TForm2 = class(TForm)
    ComboBox1: TComboBox;
    Button1: TButton;
    Button2: TButton;
    PrintDialog1: TPrintDialog;
    procedure ComboBox1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

procedure TForm2.ComboBox1Change(Sender: TObject);
begin
  printer.PrinterIndex:=ComboBox1.ItemIndex;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  ComboBox1.Items.Assign(Printer.printers);
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  Printer.BeginDoc;
  Printer.Canvas.TextOut(10,10,'Hello');
  Printer.EndDoc;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
  PrintDialog1.Execute;
end;

end.

 

Re:Printing to a non default printer under NT


A combination of a badly behaved printer driver and a flaw in the way the
DeviceMode context is refreshed when you change printers.

James.

Other Threads