Board index » cppbuilder » TPrinter.... Printer Selection

TPrinter.... Printer Selection


2007-01-21 12:23:59 AM
cppbuilder86
Hi Guy's,
I need to select a different printer to the default during the course of
a progam.
Currently PrinterIndex is set to-1 (default). It is not feasable to use
a printdialog box.
SysPrinter->Printers returns a list of 5 printers. If anyone could point
me to how
best to obatin the PrinterIndex for a printer in this list I would be
very much obliged.
SysPrinter=Printer();
SysPrinter->PrinterIndex=-1; // default
PixPerMilY=SysPrinter->PageHeight/282.0;
PixPerMilX=SysPrinter->PageWidth/202.0;
SysPrinter->Canvas->Brush->Color=clWhite;
SysPrinter->Canvas->Pen->Color=clBlack;
SysPrinter->Canvas->Pen->Width=Hpset(0.2);
SysPrinter->Orientation = poPortrait;
SysPrinter->Canvas->Font->Name="Times New Roman";
Thanks in anticipation Trevor.
 
 

Re:TPrinter.... Printer Selection

Quote
SysPrinter=Printer();
SysPrinter->PrinterIndex = SysPrinter->Printers->IndexOf(somename);
if (SysPrinter->PrinterIndex < 0)
throw Exception("Can't find printer \"" + somename + "\"");
// At this point SysPrinter now accesses the printer set above
Quote
...
HTH,
- Clayton
 

Re:TPrinter.... Printer Selection

"Clayton Arends" < XXXX@XXXXX.COM >wrote:
Quote

if (SysPrinter->PrinterIndex < 0)
throw Exception("Can't find printer \"" + somename + "\"");
That won't work as expected because if the selected printer
is the default printer, the PrinterIndex will be -1.
~ JD
 

{smallsort}

Re:TPrinter.... Printer Selection

"Trevor Stockill" < XXXX@XXXXX.COM >wrote:
Quote

[...] It is not feasable to use a printdialog box.
Why not?
How about an alternative UI? For example:
ComboBox1->Items->Assign( Printer()->Printers );
if( ComboBox1->Items->Count>0 )
{
ComboBox1->ItemIndex = 0;
}
Then when it's time to switch printers, just:
Printer()->PrinterIndex = ComboBox1->ItemIndex;
and leave it to the user to set the desired printer(s)
prior to initiating printing.
Do note however, that a system can have several printers
installed that no longer exist so selecting one of those
will cause the print to spool.
~ JD
 

Re:TPrinter.... Printer Selection

Thanks you guy's for all your help.
Problem now solved using IndexOf.
Much appreciated.
Best Regards
Trevor
Quote

 

Re:TPrinter.... Printer Selection

Correct, the exception would never get thrown. In my own tests I used a
temporary variable. Then in my post I used what I thought to be a shortcut.
Thanks for pointing that out.
- Clayton