Board index » delphi » D3 pro Printer Dialogs

D3 pro Printer Dialogs

Hello,

I made a small program for a Win95 pc, where I used a PrinterSetUpDialog and
a PrintDialog to be able to choose from the printers on the machine.
The PC has one printer on LPT1 and one on LPT2 which the dialogs presents
with right ports and names.
The print, however, is always directed to LPT1 whatever I choose from the
dialog.

The program is developed on a Win98 PC.

Any ideas of  what is going on?

Then I would be most grateful. The list should be written before the end of
this month :-)

:)
Kai Inge

 

Re:D3 pro Printer Dialogs


Forgot to mention that excel and other non-Delphi programs selects the
correct port for print, while my Delphi program does not.
That makes me feel like a jerk :-)

:)
Kai Inge

Quote

Re:D3 pro Printer Dialogs


Just using the Component doesn't set it to the default printer that the
program will use.

Can you please forward the code you use so we can see where you are going
wrong !

Thanks

Aaron

"Kai Inge Buseth" <kibus...@online.no> wrote in message
news:p9Hk9.22850$0p1.397420@news2.ulv.nextra.no...

Quote

> Forgot to mention that excel and other non-Delphi programs selects the
> correct port for print, while my Delphi program does not.
> That makes me feel like a jerk :-)

> :)
> Kai Inge

Re:D3 pro Printer Dialogs


The code goes like this:

{psetupd : TPrinterSetupDialog}

procedure Ttliste.sbF12Click(Sender: TObject);
begin
  callingform := sbF12.Owner.Name;
  {KODE}
  If psetupd.Execute then
  begin
    try
      Qtelleliste.q1.Print;
    except
    end;
  end;
end;

I would believe that the PrinterSetupDialog deals with whatever it takes to
change the output port, when the combobox selects Printer number two.
It can detect both printers, and select each of them with LPT2 coming up in
the label. Still the output goes to LPT1.

Any suggestions would be appreciated.

:)
Kai Inge

Aaron Miles <supp...@qbd.net.au> skrev i
meldingsnyheter:d4Qk9.603$U5.43...@nasal.pacific.net.au...

Quote
> Just using the Component doesn't set it to the default printer that the
> program will use.

> Can you please forward the code you use so we can see where you are going
> wrong !

> Thanks

> Aaron

> "Kai Inge Buseth" <kibus...@online.no> wrote in message
> news:p9Hk9.22850$0p1.397420@news2.ulv.nextra.no...

> > Forgot to mention that excel and other non-Delphi programs selects the
> > correct port for print, while my Delphi program does not.
> > That makes me feel like a jerk :-)

> > :)
> > Kai Inge

Re:D3 pro Printer Dialogs


"Kai Inge Buseth" <kibus...@online.no> wrote in message
news:Z3Hk9.22848$0p1.397425@news2.ulv.nextra.no...

Quote
> Hello,

> I made a small program for a Win95 pc, where I used a PrinterSetUpDialog
and
> a PrintDialog to be able to choose from the printers on the machine.
> The PC has one printer on LPT1 and one on LPT2 which the dialogs presents
> with right ports and names.
> The print, however, is always directed to LPT1 whatever I choose from the
> dialog.

> The program is developed on a Win98 PC.

> Any ideas of  what is going on?

> Then I would be most grateful. The list should be written before the end
of
> this month :-)

You need to set the Printer Object Index. The function below
takes the printer name, which you get from the PrintDialog, and sets
the index properly.
I use a repeat .. until loop and a try ..except as I found no
way to detemine the number of available printers.
You need to includes the Printers unit.

function SetPrinterIndex( const prnName : string ) : integer;
begin
 result  := 0;
 try
    repeat
      if Printer.Printers[ result ] = prnName then
      begin
        Printer.PrinterIndex := prnIndex;
        break;
      end else
        Inc( result );
    until result = 99;
  except
   result := -1;
  end;
end;

PR

Re:D3 pro Printer Dialogs


Quote
"peterr" <pet...@freemail.absa.co.za> wrote in message

news:3d954975$0$18843@hades.is.co.za...

Quote
> function SetPrinterIndex( const prnName : string ) : integer;
> begin
>  result  := 0;
>  try
>     repeat
>       if Printer.Printers[ result ] = prnName then
>       begin
>         Printer.PrinterIndex := prnIndex;    <<<====
>         break;
>       end else
>         Inc( result );
>     until result = 99;
>   except
>    result := -1;
>   end;
> end;

Line marked <<<==== should read
    Printer.PrinterIndex := result;

To expand on the whole thing.  The PrintDialog box
does virtually nothing other than return ceratin values
to be used later.
The "Printer.Printers" array holds a list of all
available printers. Always match by name as
the array position changes when a printer is
added, deleted or renamed.
The printer you are using is
  Printer.Printers[ Printer.PrinterIndex ]

PR

Re:D3 pro Printer Dialogs


On Fri, 27 Sep 2002 21:29:58 GMT, "Kai Inge Buseth" <kibus...@online.no> wrote:

Quote
>The code goes like this:

>{psetupd : TPrinterSetupDialog}

>procedure Ttliste.sbF12Click(Sender: TObject);
>begin
>  callingform := sbF12.Owner.Name;
>  {KODE}
>  If psetupd.Execute then
>  begin
>    try
>      Qtelleliste.q1.Print;
>    except
>    end;
>  end;
>end;

Here are some code snippets for getting/setting and applying a default printer.
The "cb" prefix in my code indicates a "combo box" and "lbl" is just a label.

function TfrmSetup.GetDefaultPrinter : string;
var
     ResStr : array[0..255] of char;
begin
     GetProfileString('Windows','device','',ResStr,255);
     Result:=StrPas(ResStr);
end;

procedure TfrmSetup.SetDefaultPrinter(NewDefPrinter : string);
var
   ResStr : array[0..255] of char;
begin
     StrPCopy(ResStr,NewdefPrinter);
     WriteProfileString ('windows', 'device', ResStr);
     StrCopy (ResStr, 'windows');
     SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@ResStr));
end;

procedure TfrmSetup.btnSetPrintClick(Sender: TObject);
var
   PrtrNamePort: string;
   prtrName: string;
begin
  if cbPrinter.ItemIndex > - 1 then begin
  PrtrNamePort := cbPrinter.Items[cbPrinter.ItemIndex];
  PrtrName := Copy(PrtrNamePort, 1, Pos(' on ', PrtrNamePort) - 1);
  SetDefaultPrinter(PChar(PrtrName))
  end;
  lblPrinter.caption := 'Default is '+ GetDefaultPrinter;
  btnApply.Click;
end;

Andy
The Perpetual Novice Programmer

Re:D3 pro Printer Dialogs


Thank you for answering me.
I have some difficulties to understand the connection between your code and
the TPrinterSetupDialog.
Where do I put your code, and how does it intercept the closeup and change
of the combobox in the Dialog Form.
Where do TPrinterSetupDialog store it's list values?
It has rather few properties. I have tried with prnName :=
TPrinterSetupDialog.Name;
but to no avail. prnIndex was also a undecleared identifier, am I supposed
to
prnIndex := result; somewhere?
How do I connect the text in the combobox to prnName when it's changed since
there do not seem to be a
oncloseup or onchange event available?
I understand the most of your code, but not where to put it and how to
connect it to the Dialog's combobox changes.

:)
Kai Inge

peterr <pet...@freemail.absa.co.za> skrev i
meldingsnyheter:3d95b922$0$18...@hades.is.co.za...

Quote

> "peterr" <pet...@freemail.absa.co.za> wrote in message
> news:3d954975$0$18843@hades.is.co.za...

> > function SetPrinterIndex( const prnName : string ) : integer;
> > begin
> >  result  := 0;
> >  try
> >     repeat
> >       if Printer.Printers[ result ] = prnName then
> >       begin
> >         Printer.PrinterIndex := prnIndex;    <<<====
> >         break;
> >       end else
> >         Inc( result );
> >     until result = 99;
> >   except
> >    result := -1;
> >   end;
> > end;

> Line marked <<<==== should read
>     Printer.PrinterIndex := result;

> To expand on the whole thing.  The PrintDialog box
> does virtually nothing other than return ceratin values
> to be used later.
> The "Printer.Printers" array holds a list of all
> available printers. Always match by name as
> the array position changes when a printer is
> added, deleted or renamed.
> The printer you are using is
>   Printer.Printers[ Printer.PrinterIndex ]

> PR

Re:D3 pro Printer Dialogs


On Sun, 29 Sep 2002 21:13:31 GMT, "Kai Inge Buseth" <kibus...@online.no> wrote:

Quote
>Thank you for answering me.

No sweat.

Quote
>I have some difficulties to understand the connection between your code and
>the TPrinterSetupDialog.

That's because there really isn't any.  This is stuff I acquired (in this group) to overcome a
similar problem (as I understood your post).

Quote
>Where do I put your code, and how does it intercept the closeup and change
>of the combobox in the Dialog Form.

With this or similar code you can negate using the PSD altogether.  Set your own default as
required.  Keep in mind that the code I quoted you is lifted directly from one of my apps, so some
of the stuff won't seem very relevant.  It isn't commented because I assumed (there's that word
again <g>) that the function and procedures were self explanatory.  

Messing around with the printer dialog isn't one of my forte's.  My signature line, speaks the
truth.  ;-)

Andy
The Perpetual Novice Programmer

Re:D3 pro Printer Dialogs


Thank you,

I will try it out. It takes some time to try out the different solutions
because the PC with two printers is in the other end of the town :-)
It is an older PC with Win 95.
Since there are only two printers, one in LPT1 and one in LPT2 I tried to
set the Printers.Printerindex directly to 0 and 1 accordingly,
but with no response.

So now I will go on to explore your code to see if it can make the Win 95
obey :-)
(It was much easier in the earlier days, when the only thing I had to do was
to adress the LPT1/LPT2 directly.)

:)
Kai Inge

Andy <ptra...@nospamat.rogers.com> skrev i
meldingsnyheter:3d989845.8748...@nntp.bloor.is.net.cable.rogers.com...

Quote
> On Sun, 29 Sep 2002 21:13:31 GMT, "Kai Inge Buseth" <kibus...@online.no>
wrote:

> >Thank you for answering me.
> No sweat.

> >I have some difficulties to understand the connection between your code
and
> >the TPrinterSetupDialog.
> That's because there really isn't any.  This is stuff I acquired (in this

group) to overcome a
Quote
> similar problem (as I understood your post).

> >Where do I put your code, and how does it intercept the closeup and
change
> >of the combobox in the Dialog Form.

> With this or similar code you can negate using the PSD altogether.  Set
your own default as
> required.  Keep in mind that the code I quoted you is lifted directly from

one of my apps, so some
Quote
> of the stuff won't seem very relevant.  It isn't commented because I

assumed (there's that word
Quote
> again <g>) that the function and procedures were self explanatory.

> Messing around with the printer dialog isn't one of my forte's.  My

signature line, speaks the
Quote
> truth.  ;-)

> Andy
> The Perpetual Novice Programmer

Re:D3 pro Printer Dialogs


"Kai Inge Buseth" <kibus...@online.no> wrote in message
news:%1Kl9.24072$0p1.413227@news2.ulv.nextra.no...

Quote
> Thank you for answering me.
> I have some difficulties to understand the connection between your code
and
> the TPrinterSetupDialog.

I usually just use a combobox to list the printers for selection and rely on
the
printer setup to hold the correct values, such as paper size, orientation,
etc.
For preview selection, etc, I have my own form. TPrinterSetupDialog is
rather the pits.

In the Form.Create() event insert
     cbPrinters.Items   := Printer.Printers;

Select the printer from the list. Use the function provided to set
the global Printer Object. The point to put the code is before
the report is called.
My strategy is to set up the printer stuff as globally accessible
default values, so that when it comes to printing the user only
has to press the <Print> button, unless they want to do something
special. My assumption is that most of the printing always goes
to a specific printer which is also set up for that job.

Quote
> Where do I put your code, and how does it intercept the closeup and change
> of the combobox in the Dialog Form.
> Where do TPrinterSetupDialog store it's list values?
> It has rather few properties. I have tried with prnName :=
> TPrinterSetupDialog.Name;
> but to no avail. prnIndex was also a undecleared identifier, am I supposed
> to
> prnIndex := result; somewhere?

prnIndex would be an integer.

Quote
> How do I connect the text in the combobox to prnName when it's changed
since
> there do not seem to be a
> oncloseup or onchange event available?

I think there are no events. The dialog box only returns TRUE or FALSE
depending on the OK or Close button. All other stuff should be in the
properties. As I don't use it I am a bit vague about this.

Quote
> I understand the most of your code, but not where to put it and how to
> connect it to the Dialog's combobox changes.

I'll e-mail some more detailed code/explanations to you, but that may
take a day or two until I get to it.

PR

Quote
> peterr <pet...@freemail.absa.co.za> skrev i
> meldingsnyheter:3d95b922$0$18...@hades.is.co.za...

> > "peterr" <pet...@freemail.absa.co.za> wrote in message
> > news:3d954975$0$18843@hades.is.co.za...

> > > function SetPrinterIndex( const prnName : string ) : integer;
> > > begin
> > >  result  := 0;
> > >  try
> > >     repeat
> > >       if Printer.Printers[ result ] = prnName then
> > >       begin
> > >         Printer.PrinterIndex := prnIndex;    <<<====
> > >         break;
> > >       end else
> > >         Inc( result );
> > >     until result = 99;
> > >   except
> > >    result := -1;
> > >   end;
> > > end;

> > Line marked <<<==== should read
> >     Printer.PrinterIndex := result;

> > To expand on the whole thing.  The PrintDialog box
> > does virtually nothing other than return ceratin values
> > to be used later.
> > The "Printer.Printers" array holds a list of all
> > available printers. Always match by name as
> > the array position changes when a printer is
> > added, deleted or renamed.
> > The printer you are using is
> >   Printer.Printers[ Printer.PrinterIndex ]

> > PR

Re:D3 pro Printer Dialogs


Thanks,

when you explained that the code has no connection with the native
TPrinterSetupDialog I understand more.
What I don't understand is why 'manually by code' change of the
Printers.PrinterIndex do not change printers.
(Win 95)

:)
Kai Inge

peterr <pet...@freemail.absa.co.za> skrev i
meldingsnyheter:3d990f4b$0$18...@hades.is.co.za...

Quote

> "Kai Inge Buseth" <kibus...@online.no> wrote in message
> news:%1Kl9.24072$0p1.413227@news2.ulv.nextra.no...
> > Thank you for answering me.
> > I have some difficulties to understand the connection between your code
> and
> > the TPrinterSetupDialog.

> I usually just use a combobox to list the printers for selection and rely
on
> the
> printer setup to hold the correct values, such as paper size, orientation,
> etc.
> For preview selection, etc, I have my own form. TPrinterSetupDialog is
> rather the pits.

> In the Form.Create() event insert
>      cbPrinters.Items   := Printer.Printers;

> Select the printer from the list. Use the function provided to set
> the global Printer Object. The point to put the code is before
> the report is called.
> My strategy is to set up the printer stuff as globally accessible
> default values, so that when it comes to printing the user only
> has to press the <Print> button, unless they want to do something
> special. My assumption is that most of the printing always goes
> to a specific printer which is also set up for that job.

> > Where do I put your code, and how does it intercept the closeup and
change
> > of the combobox in the Dialog Form.
> > Where do TPrinterSetupDialog store it's list values?
> > It has rather few properties. I have tried with prnName :=
> > TPrinterSetupDialog.Name;
> > but to no avail. prnIndex was also a undecleared identifier, am I
supposed
> > to
> > prnIndex := result; somewhere?

> prnIndex would be an integer.

> > How do I connect the text in the combobox to prnName when it's changed
> since
> > there do not seem to be a
> > oncloseup or onchange event available?

> I think there are no events. The dialog box only returns TRUE or FALSE
> depending on the OK or Close button. All other stuff should be in the
> properties. As I don't use it I am a bit vague about this.

> > I understand the most of your code, but not where to put it and how to
> > connect it to the Dialog's combobox changes.

> I'll e-mail some more detailed code/explanations to you, but that may
> take a day or two until I get to it.

> PR

> > peterr <pet...@freemail.absa.co.za> skrev i
> > meldingsnyheter:3d95b922$0$18...@hades.is.co.za...

> > > "peterr" <pet...@freemail.absa.co.za> wrote in message
> > > news:3d954975$0$18843@hades.is.co.za...

> > > > function SetPrinterIndex( const prnName : string ) : integer;
> > > > begin
> > > >  result  := 0;
> > > >  try
> > > >     repeat
> > > >       if Printer.Printers[ result ] = prnName then
> > > >       begin
> > > >         Printer.PrinterIndex := prnIndex;    <<<====
> > > >         break;
> > > >       end else
> > > >         Inc( result );
> > > >     until result = 99;
> > > >   except
> > > >    result := -1;
> > > >   end;
> > > > end;

> > > Line marked <<<==== should read
> > >     Printer.PrinterIndex := result;

> > > To expand on the whole thing.  The PrintDialog box
> > > does virtually nothing other than return ceratin values
> > > to be used later.
> > > The "Printer.Printers" array holds a list of all
> > > available printers. Always match by name as
> > > the array position changes when a printer is
> > > added, deleted or renamed.
> > > The printer you are using is
> > >   Printer.Printers[ Printer.PrinterIndex ]

> > > PR

Other Threads