Board index » cppbuilder » TPrinter and net printers

TPrinter and net printers


2005-01-29 04:16:28 AM
cppbuilder9
Hi,
I use TPrinter to create a custom report, but when I select a net
printer different than default printer, my report is printed on default
printer -_-
//------------------------------------
TPrinter *printer = new TPrinter;
if (PrintDialog->Execute())
{
printer->BeginDoc();
//code to fill canvas
printer->EndDoc();
}
delete printer;
//------------------------------------
What about this problem? Any suggest is welcome!
Mario Sernicola
 
 

Re:TPrinter and net printers

Mario Sernicola wrote:
Quote
Hi,

I use TPrinter to create a custom report, but when I select a net
printer different than default printer, my report is printed on default
printer -_-

//------------------------------------

TPrinter *printer = new TPrinter;

if (PrintDialog->Execute())
{
printer->BeginDoc();
//code to fill canvas
printer->EndDoc();
}

delete printer;

//------------------------------------

What about this problem? Any suggest is welcome!

Mario Sernicola
Use the API function EnumPrinters to get the name, etc. of the printer
you want. Use this name as an argument to the TPrinter->SetPrinter
function.
 

Re:TPrinter and net printers

Mario Sernicola wrote:
Quote
I use TPrinter to create a custom report, but when I select a net
printer different than default printer, my report is printed on default
printer -_-
Please show the code where you choose the printer.
Quote
TPrinter *printer = new TPrinter;
You are not supposed to do that.
Use
TPrinter *printer = TPrinter();
instead. And do not delete.
Hans.
 

{smallsort}

Re:TPrinter and net printers

Hans Galema wrote:
Quote
Please show the code where you choose the printer.
Hans.
How can I set printer retrieving TPrintDialog selected printer? This is
my problem.
Mario Sernicola
 

Re:TPrinter and net printers

Mario Sernicola wrote:
Quote
How can I set printer retrieving TPrintDialog selected printer? This is
my problem.
The user chooses with TPrintDialog a printer. The printer
then is set bij the PrintDialog. So you do not
need to set the printer yourself.
RichEdit1->Print() wil print to the selected printer then.
And Printer()->.... too.
Hans.
 

Re:TPrinter and net printers

Mario Sernicola < XXXX@XXXXX.COM >wrote:
Quote

How can I set printer retrieving TPrintDialog selected printer?
I never use that dialog myself. I assign the list of printers
to a ComboBox:
prnComboBox->Items->Assign( Printer()->Printers );
and then use it's item index as the value that should be assigned to the printer index:
Printer()->PrinterIndex = prnComboBox->ItemIndex;
If the user doesn't select a printer from the ComboBox, it's
item index will be -1 which translates to the default printer.
~ JD
 

Re:TPrinter and net printers

JD wrote:
Quote
I never use that dialog myself. I assign the list of printers
to a ComboBox:

prnComboBox->Items->Assign( Printer()->Printers );

and then use it's item index as the value that should be assigned to the printer index:

Printer()->PrinterIndex = prnComboBox->ItemIndex;

Ok... this is a possibility... but what about using TPrinterDialog?
Mario Sernicola
 

Re:TPrinter and net printers

Mario Sernicola < XXXX@XXXXX.COM >wrote:
Quote

[...] but what about using TPrinterDialog?
What about it? It doesn't give you anything that you can't
easily do yourself. Granted, using the dialog means that you
don't have to code (much of) anything but it also means that
you have to use a GUI designed by someone else.
~ JD
 

Re:TPrinter and net printers

JD wrote:
Quote
What about it? ...
~ JD
I like to know how I can retrieve printer selected by a TPrinterDialog
and assign it to TPrinter object, in order to print on any other net
printer and not only on default printer.
Mario Sernicola
 

Re:TPrinter and net printers

Mario Sernicola wrote:
Quote
I like to know how I can retrieve printer selected by a TPrinterDialog
and assign it to TPrinter object,
You were already told that the by the user selected printer is
automatically assigned as default printer for TPrinter().
So this was twice.
Hans.
 

Re:TPrinter and net printers

Hans Galema wrote:
Quote
You were already told that the by the user selected printer is
automatically assigned as default printer for TPrinter().

So this was twice.

Hans.
No... Even if I chose another printer by TPrinterDialog, TPrinter use
default printer because I can't set the TPrinter->PrinterIndex property.
Mario Sernicola
 

Re:TPrinter and net printers

Mario Sernicola wrote:
Quote
No... Even if I chose another printer by TPrinterDialog, TPrinter use
default printer because I can't set the TPrinter->PrinterIndex property.
No it does not. And you do not have to set PrinterIndex. And of course
you can always set PrinterIndex as that has nothing to do wit TPrintDialog.
Please show your code now.
Hans.
 

Re:TPrinter and net printers

Hans Galema wrote:
Quote
Please show your code now.

Hans.
My code is something like that:
//------------------------------------
TPrinter *printer = new TPrinter();
if (PrintDialog->Execute())
{
printer->BeginDoc();
//code to fill canvas
printer->EndDoc();
}
delete printer;
//------------------------------------
In TPrinterDialog I can choose a net printer, but I don't select any
printern in my TPrinter object, so I finally print on default printer. I
would like to retrieve the printer that I've selected by TPrinterDialog
and assign it to TPrinter
Mario Sernicola
 

Re:TPrinter and net printers

Mario Sernicola < XXXX@XXXXX.COM >wrote:
Quote
Hans Galema wrote:

>Please show your code now.
>
>Hans.

My code is something like that:

//------------------------------------

TPrinter *printer = new TPrinter();
Hans already told you to not 'new' the printer. Just use the
global Printer() object instead:
Printer()->BeginDoc();
~ JD