[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Change Printer/ Get new Information

Posted on 2000-01-17
11
Medium Priority
?
441 Views
Last Modified: 2010-04-06
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

0
Comment
Question by:hbrasch
  • 5
  • 2
  • 2
  • +2
11 Comments
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 2359245
Why not post this question to Borland ?!!
0
 

Expert Comment

by:brunohe
ID: 2359258
Try to call TPrinter.Refresh after setting the printerindex
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2359264
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 

Author Comment

by:hbrasch
ID: 2359282
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
 

Accepted Solution

by:
brunohe earned 600 total points
ID: 2359306
or try to call TPrinter.SetPrinter directly....
0
 
LVL 1

Expert Comment

by:Indefrei
ID: 2360340
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
 
LVL 1

Expert Comment

by:Indefrei
ID: 2360403
Oops...
Sorry
i killed CONST dmDefaultSource, when cutting the source
Button3Click was just for testing
cheers
Indi
0
 
LVL 1

Expert Comment

by:Indefrei
ID: 2360453
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
 
LVL 1

Expert Comment

by:Indefrei
ID: 2368902
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
 

Author Comment

by:hbrasch
ID: 2380721
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
 
LVL 1

Expert Comment

by:Indefrei
ID: 2386521
schön für dich, Heinz
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Suggested Courses

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question