Change Printer/ Get new Information

hi out there...

i´ve got a problem. I got 2 SONY
UP-D2500 Printer. One on LPT1 one
one LPT2. The printer on LPT2 is
prepared for printing sticker, the
other one for postcards also defined as standard printer. Now i want
to change the printeroutput
with Tprinter.printerindex. No problem
but when i´ll try to get the dimensions
of the printer (Tprinter.pagewidth and
pageheight) delphi gives me the
dimenstion of the default printer. naughty naughty delphi... the other way,
wenn I define the sticker printer as
default, and i want to print postcards... i´ll only retriev the stickerheight and width ... no chance
for me at the moment.

what i want is the print on the postcards printer, retriev the postcards printer dimensions and when i want to print on the sticker printer, i´ll want to retriev the sticker size !

please help,
Heinz

hbraschAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PeterLarsenCommented:
Why not post this question to Borland ?!!
0
brunoheCommented:
Try to call TPrinter.Refresh after setting the printerindex
0
TheNeilCommented:
Heinz

I don;t have exactly the same setup as you but there are 2 printers attached to my machine and the following code DOES correctly return the page width and height data from each of them.

PROCEDURE TForm1.Button1Click(Sender: TObject);
VAR
  n : INTEGER;
begin
  ListBox1.Items.Assign(Printer.Printers);
  FOR n := 0 TO (ListBox1.Items.Count - 1)
  DO
  BEGIN
    Printer.PrinterIndex := n;
    ListBox1.Items[n] := ListBox1.Items[n] + ' [' + IntToStr(Printer.PageWidth) + 'x' + IntToStr(Printer.PageHeight) + ']';
  END;
end;

This will at least prove that Delphi is aware of both your printers. As to why it's getting the dimensions wrong on your system then it could be Windows trying to do something 'clever'.

The Neil
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

hbraschAuthor Commented:
To PeterLarsen:
I´ll do too.

To BrunoHe:
Didn´t work ! I´ll tried allready!

To TheNeil:
noep, that didn´t work... both printer
got the same dimension.

Step by step i think that´s because
both printer are using the same
driver....  

thanks
Heinz
0
brunoheCommented:
or try to call TPrinter.SetPrinter directly....
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IndefreiCommented:
Hi, something simular was given once by Raymond

unit PrinterDevices1;

interface

uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,  StdCtrls, Printers;
const
                  DM_ORIENTATION = 1;
                  DM_PAPERSIZE = 2;
                  DM_PAPERLENGTH = 4;
                  DM_PAPERWIDTH = 8;
                 

type
                  TForm1 = class(TForm)
                    Button1: TButton;
                    Memo1: TMemo;
                    Button2: TButton;
                    PrinterSetupDialog1: TPrinterSetupDialog;
                    Button3: TButton;
                     
                    procedure Button2Click(Sender: TObject);
                    procedure Button3Click(Sender: TObject);
                  private
                    { Private-Deklarationen }
                  public
                    { Public-Deklarationen }
                  end;

var
                  Form1: TForm1;

implementation

                {$R *.DFM}


procedure TForm1.Button2Click(Sender: TObject);var
                ADevice, ADriver, APort: array [0..255] of char;
                ADeviceMode: THandle;
                DevMode: PDevMode;
begin
               with Printer do
               begin
                      GetPrinter(ADevice,ADriver,APort,ADeviceMode);
                      DevMode := GlobalLock(ADeviceMode);
                      if not Assigned(DevMode) then showMessage('can't find printer')
               else
               begin
                           with DevMode^ do
                           begin

                           memo1.lines.add('Source ' + IntToStr(dmDefaultSource));            // check
                the constants
                           memo1.lines.add('Orientation ' + IntToStr(dmOrientation));            // check
                the constants
                           memo1.lines.add('Papersize ' + IntToStr(dmPaperSize));            // check the
                constants
                end;
         end;

 //  etc.
// HAVE A LOOK INTO WINDOWS.PAS FOR MANY MORE CHOICES !!!

                       GlobalUnlock(ADeviceMode);
                  end;
           end;

                {   Here's the TDevMode structure with all the things you can change like
                   this:

                   _devicemodeA = packed record
                   dmDeviceName: array[0..CCHDEVICENAME - 1] of AnsiChar;
                   dmSpecVersion: Word;
                   dmDriverVersion: Word;
                   dmSize: Word;
                   dmDriverExtra: Word;
                   dmFields: DWORD;
                   dmOrientation: SHORT;
                   dmPaperSize: SHORT;
                   dmPaperLength: SHORT;
                   dmPaperWidth: SHORT;
                   dmScale: SHORT;
                   dmCopies: SHORT;
                   dmDefaultSource: SHORT;
                   dmPrintQuality: SHORT;
                   dmColor: SHORT;
                   dmDuplex: SHORT;
                   dmYResolution: SHORT;
                   dmTTOption: SHORT;
                   dmCollate: SHORT;
                   dmFormName: array[0..CCHFORMNAME - 1] of AnsiChar;
                   dmLogPixels: Word;
                   dmBitsPerPel: DWORD;
                   dmPelsWidth: DWORD;
                   dmPelsHeight: DWORD;
                   dmDisplayFlags: DWORD;
                   dmDisplayFrequency: DWORD;
                   dmICMMethod: DWORD;
                   dmICMIntent: DWORD;
                   dmMediaType: DWORD;
                   dmDitherType: DWORD;
                   dmICCManufacturer: DWORD;
                   dmICCModel: DWORD;
                   dmPanningWidth: DWORD;
                   dmPanningHeight: DWORD;
                   end; }

                procedure TForm1.Button3Click(Sender: TObject);
                begin
                     printersetupdialog1.Execute;
                end;

                end.

To Change Printer with Printer.PrinterIndex should work
but you could also use  
          SetPrinter(ADevice,ADriver,APort,ADeviceMode);

Good Luck
Indi
0
IndefreiCommented:
Oops...
Sorry
i killed CONST dmDefaultSource, when cutting the source
Button3Click was just for testing
cheers
Indi
0
IndefreiCommented:
Oh oh...
forgot button1, too

procedure TForm1.Button1Click(Sender: TObject);
var
ADevice, ADriver, APort: array [0..255] of char;
ADeviceMode:          THandle;
DevMode: PDevMode;
begin    with Printer do begin
                                          GetPrinter(ADevice,ADriver,APort,ADeviceMode);
                                          SetPrinter(ADevice,ADriver,APort,0);
                                          GetPrinter(ADevice,ADriver,APort,ADeviceMode);
DevMode := GlobalLock(ADeviceMode);
if not Assigned(DevMode) then ShowMessage('Can''t set printer.')
else begin        
with DevMode^ do begin
       {Put any other settings you want here}
        dmDefaultSource := DMBIN_UPPER;
 {these codes are listed in "Windows.pas"}    
   end;
  GlobalUnlock(ADeviceMode);
                                            SetPrinter(ADevice,ADriver,APort,ADeviceMode);    
  end;
end;

Printer.BeginDoc;
 Printer.Canvas.TextOut(50,50,'This page is printing from the UPPER  PAPER TRAY.');
 with DevMode^ do begin
      {Put any other settings you want   here}
  dmDefaultSource := DMBIN_LOWER;
      {these codes are listed in "Windows.pas"}  
 end;
Printer.NewPageDC(DevMode);
Printer.Canvas.TextOut(50,50,'This page is printing from the LOWER PAPER TRAY.');
Printer.EndDoc;
end;
....
Sorry, have some problems formatting the ExEx page, too
0
IndefreiCommented:
Heinz,
you could try a little dirty
duplicate the printers.pas unit to myprinters.pas and change
the printer unit
just a thought...
Indi
0
hbraschAuthor Commented:
yes, i´ll tried this many times before... but now, magically it works
fine... now i access the printers
over the name in the printerlist and
all properties will work..

procedure tform.print;
var adevicemode : thandle;
begin
 adevicemode:=0;
 printer.setprinter(pchar(Printername),
                    #0,#0,adevicemode);


end;

thanx, Heinz

0
IndefreiCommented:
schön für dich, Heinz
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.