Board index » delphi » T-Shirt if you can solve my problem (Seriously)

T-Shirt if you can solve my problem (Seriously)

The person who gives me the best solution to this problem will get a T-Shirt.  
Because I'm in South Africa, I can't send dollars so an ethnic t-shirt will
have to do.  Unfortunately charged for support doesn't work either.

Problem as follows:

I have to communicate with the Wang OCX to print a tif file.  The parameters
that I'm having a problem with are the printer options.  The OCX requires the
following (amongst others) in the PrintImage method...

Printer              String  The name of the printer
Driver                String  The name of the printer driver
PortNumber      String  The name of the output port

How on do I get these strings (or pChars) after a user has selected a printer
using the TPrintDialog component?  What are the API calls.

T-Shirt to follow.

Cheers, Simon

 

Re:T-Shirt if you can solve my problem (Seriously)


Hello Simon,

After changing the settings with the TPrinterSetupDialog use
the Printer.GetPrinter method. For example:

procedure TForm1.Button1Click(Sender: TObject);
var
  Name,Driver,Port : Array [0..255] of char;
  H : THandle;
begin
  PrinterSetupDialog1.Execute;
  Printer.GetPrinter (Name,Driver,Port,H);
  ShowMessage (String(Name)+','+ String(Driver)+','+String(Port));
end;

Hope this help!!

Daniel.

--=20
-------------------------------------------------------------------------=
-
Daniel Polistchuck      Systems Analyst
dan...@pobox.com       Technology Group
                        Simples Information Technology
                        dan...@simples.com.br
-------------------------------------------------------------------------=
-

Quote
> si...@delphi.co.za (Simon Munro) wrote in article =

<4phppk$...@newnews.iafrica.com>...
Quote
> The person who gives me the best solution to this problem will get a =
T-Shirt. =20
> Because I'm in South Africa, I can't send dollars so an ethnic t-shirt =
will=20
> have to do.  Unfortunately charged for support doesn't work either.
>=20
> Problem as follows:
>=20
> I have to communicate with the Wang OCX to print a tif file.  The =
parameters=20
> that I'm having a problem with are the printer options.  The OCX =
requires the=20
> following (amongst others) in the PrintImage method...
>=20
> Printer              String  The name of the printer
> Driver                String  The name of the printer driver
> PortNumber      String  The name of the output port
>=20
> How on do I get these strings (or pChars) after a user has selected a =
printer=20
> using the TPrintDialog component?  What are the API calls.
>=20
> T-Shirt to follow.
>=20
> Cheers, Simon

Re:T-Shirt if you can solve my problem (Seriously)


Daniel Polistchuck from Unisys Brasil Ltda. (Sao Paulo - Brazil) is soon to be
the proud owner of a South African T-Shirt!

I had an answer to my question (that has been asked here before) in in a few
hours... Maybe I've stumbled onto a new form of paid-for support.

Cheers, Simon

Re:T-Shirt if you can solve my problem (Seriously)


On Mon, 10 Jun 96 18:30:08 GMT, si...@delphi.co.za (Simon Munro)
wrote:

Quote
>I have to communicate with the Wang OCX to print a tif file.  The parameters
>that I'm having a problem with are the printer options.  The OCX requires the
>following (amongst others) in the PrintImage method...

>Printer              String  The name of the printer
>Driver                String  The name of the printer driver
>PortNumber      String  The name of the output port

>How on do I get these strings (or pChars) after a user has selected a printer
>using the TPrintDialog component?  What are the API calls.

Call Printer.GetPrinter.

You must allocate space for the Device (printer), driver, and port
strings, to pass PChar pointers to GetPrinter. (The documentation is
not very clear on this.)

--
Ray Lischner                              li...@tempest-sw.com
Tempest Software, Corvallis, Oregon, USA  http://www.tempest-sw.com

Re:T-Shirt if you can solve my problem (Seriously)


Quote
Simon Munro wrote:

> The person who gives me the best solution to this problem will get a T-Shirt.
> Because I'm in South Africa, I can't send dollars so an ethnic t-shirt will
> have to do.  Unfortunately charged for support doesn't work either.

> Problem as follows:

> I have to communicate with the Wang OCX to print a tif file.  The parameters
> that I'm having a problem with are the printer options.  The OCX requires the
> following (amongst others) in the PrintImage method...

> Printer              String  The name of the printer
> Driver                String  The name of the printer driver
> PortNumber      String  The name of the output port

> How on do I get these strings (or pChars) after a user has selected a printer
> using the TPrintDialog component?  What are the API calls.

> T-Shirt to follow.

> Cheers, Simon

Simon,

Following is the code that will get you the information you need regarding printer names, ports,
and drivers.  This method is not as clean as is possible using the direct Windows API, but
because Delphi has wrapped the Printer Dialog into a component, this is the best I could do.  

If you wanted to use the API to call the Print Dialog directly, there is a parameter returned
which contains the information you need.  This method is more direct, but requires a more
detailed understanding of the Windows API.  If you need the information about calling the Print
Dialog directly, I can forward that information as well.

Basically the method below uses the 'win.ini' file to gather the driver information about the
current printer (which can be determined from the Delphi Printer (TPrinter) variable.

Best of luck,
Blake Schwendiman

------------------------

{
    This unit contains all of the code necessary to determine the current
    printer name, driver, and port.  The related form consists of a button
    named 'Button1', three labels ('Labe1', 'Label2', 'Label3'), and a
    printer dialog component named 'PrintDialog'.

    When the program is executed, the form displays the currently selected
    printer.  On pushing 'Button1', the printer dialog is shown and the user
    may select a new printer.  When the dialog is closed, the form re-displays
    the current printer information.  It may or may not have changed.

Quote
}

unit Main;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, IniFiles, Printers;

type
  TForm1 = class(TForm)
    Button1: TButton;
    PrintDialog: TPrintDialog;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    procedure UpdatePrinterLabels;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
    PrintDialog.Execute;
    UpdatePrinterLabels;
end;

procedure TForm1.UpdatePrinterLabels;
var
    winIni        : TIniFile;
    comma         : Integer;
    printerName   : String;
    driver        : String;
    port          : String;
    printerString : String;
    index         : Integer;
    onLoc         : Integer;
begin
    {
        The Printer variable contains a member called Printers which is a
        list of all printers and assigned ports.  An entry looks like:
            'HP Laser 5P on LPT1:'

        The PrinterIndex variable indicates which entry in the Printers list
        is active.

        Using this info, get the current printer string and parse it into
        the printer name and the printer port.
    }
    printerString := Printer.Printers[Printer.PrinterIndex];
    onLoc         := Pos( 'on', printerString );
    printerName   := Copy( printerString, 1, onLoc - 2 );
    Delete( printerString, 1, onLoc + 2 );
    port          := printerString;

    {
        The driver information associated with each printer is stored in the
        Windows Initialization file.  The section 'Devices' contains entries
        that look like:
             printerName=printerDriver,printerPort

        Using this info, read the appropriate entry, and parse off the
        driver name.
    }
    winIni := TIniFile.Create( 'win.ini' );
    printerString := winIni.ReadString( 'Devices', printerName, 'none,none' );
    winIni.Free;

    comma   := Pos( ',', printerString );
    driver  := Copy( printerString, 1, comma - 1 );

    Label1.Caption := printerName;
    Label2.Caption := driver;
    Label3.Caption := port;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
    UpdatePrinterLabels;
end;

end.

Other Threads