Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Impresión (https://www.clubdelphi.com/foros/forumdisplay.php?f=4)
-   -   QRPrintSetup actualizar impresora seleccionada (https://www.clubdelphi.com/foros/showthread.php?t=83374)

jonydread 11-06-2013 06:05:18

QRPrintSetup actualizar impresora seleccionada
 
1 Archivos Adjunto(s)
Buenas noches desde aca, les cuento tengo un quickrep, con una preview personalizada esta agrege botones con una coolbar, al boton imprimir le puse el sgte codigo y si cambio la impresora le da igual siempre me tira la impresion a la misma impresora, aca en el foro hay temas sobre esto pero no encontre una solucion
Código Delphi [-]
procedure TPreview.ToolButton1Click(Sender: TObject);
begin
reporteform.quickrep1.QRPrinter.PrintSetup;
if reporteform.quickrep1.QRPrinter.Master.tag = 0 then
        reporteform.quickrep1.QRPrinter.Print;
end;
adjunto custompreview.pas

saludos

marcoszorrilla 11-06-2013 07:26:07

Yo hago esto:
Código Delphi [-]
procedure TfrConclientes.SpeedButton4Click(Sender: TObject);
begin
Application.CreateForm(TfrlstClientes, frlstClientes);
frlstClientes.ListaClientes.PrinterSettings.PrinterIndex:=GetImpresora(Impresora4);
frlstClientes.ListaClientes.Print;
frlstClientes.Close;
end;

Un Saludo

marcoszorrilla 11-06-2013 07:28:48

Añado la función que selecciona la impresora, por ejemplo la que este configuradad para Facturas, Pedidos, Listados...
Código Delphi [-]
Function GetImpresora(Impre:String):Integer;
Var
nCont:Integer;
lSearch:Boolean;
cNewLIne:String;
begin
lSearch:=False;
cNewLine:=Chr(10)+Chr(13);

  For nCont:=0 to Printer.Printers.Count - 1 do
  //buscamos la impresora en la lista del sistema
  begin

      if Pos(impre, Printer.Printers[nCont]) <> 0 then
      begin
      lSearch:=True;
      Result:=nCont;
      Break;
      end;

  end;

  if lSearch = False then
  begin
  ShowMessage('Impresora no encontrada.'+impre+cNewLine+'Se utilizará la predeterminda.');
  Result:=-1
  end;

end;
Un Saludo.

jonydread 12-06-2013 07:13:55

lo realizo asi y dice GetImpresora undeclared identifier
en el quickrep
Código Delphi [-]
procedure TReporteForm.QuickRep1BeforePrint(Sender: TCustomQuickRep;
  var PrintReport: Boolean);
begin
QuickRep1.PrinterSettings.Printerindex:=GetImpresora(qrPrinter.PrinterIndex);
end;

Function GetImpresora(Impre:String):Integer;
Var
nCont:Integer;
lSearch:Boolean;
cNewLIne:String;
begin
lSearch:=False;
cNewLine:=Chr(10)+Chr(13);

  For nCont:=0 to Printer.Printers.Count - 1 do
  //buscamos la impresora en la lista del sistema
  begin

      if Pos(impre, Printer.Printers[nCont]) <> 0 then
      begin
      lSearch:=True;
      Result:=nCont;
      Break;
      end;

  end;

  if lSearch = False then
  begin
  ShowMessage('Impresora no encontrada.'+impre+cNewLine+'Se utilizará la predeterminda.');
  Result:=-1
  end;

end;
en boton del QRPreview
Código Delphi [-]
procedure TPreview.ToolButton1Click(Sender: TObject);
begin
reporteform.quickrep1.QRPrinter.PrintSetup;
if reporteform.quickrep1.QRPrinter.Master.tag = 0 then
        reporteform.quickrep1.QRPrinter.Print;

end;
que hago mal??

ecfisa 12-06-2013 16:34:50

Cita:

Empezado por jonydread (Mensaje 462116)
lo realizo asi y dice GetImpresora undeclared identifier
...
que hago mal??

Hola jonydread.
Código Delphi [-]
Function GetImpresora(Impre:String):Integer;
Var
  nCont:Integer;
  lSearch:Boolean;
  cNewLIne:String;
begin
  lSearch:=False;
  cNewLine:=Chr(10)+Chr(13);
  For nCont:=0 to Printer.Printers.Count - 1 do
  //buscamos la impresora en la lista del sistema
  begin
      if Pos(impre, Printer.Printers[nCont]) <> 0 then
      begin
      lSearch:=True;
      Result:=nCont;
      Break;
      end;
  end;
  if lSearch = False then
  begin
  ShowMessage('Impresora no encontrada.'+impre+cNewLine+'Se utilizará la predeterminda.');
  Result:=-1
  end;
end;

procedure TReporteForm.QuickRep1BeforePrint(Sender: TCustomQuickRep;
  var PrintReport: Boolean);
begin
QuickRep1.PrinterSettings.Printerindex:=GetImpresora(qrPrinter.PrinterIndex);
end;
GetImpresora es una función y a diferencia de un método, su declaración tiene que preceder en órden al código que la invoca.

Saludos. :)

jonydread 13-06-2013 05:10:59

creo que el problema esta en
Código Delphi [-]
GetImpresora(QRPrinter.PrinterIndex)

no se puede utilizar QRPrinter.PrinterIndex y dice Returnvalue of function GetImpresora migth be undefined si dejo vacio para probar el error y es lo mismo

como puedo obtener la impresora seleccionada en el printsetup qe esta en preview del quickrep
Código Delphi [-]
reporteform.quickrep1.QRPrinter.PrintSetup

jonydread 13-06-2013 06:48:38

he quitado el error pero no obtener la impresora seleccionada :confused:
Código Delphi [-]
procedure TPreview.ToolButton1Click(Sender: TObject);
  var
simp:string;
begin
ReporteForm.quickrep1.QRPrinter.printsetup;
if ReporteForm.quickrep1.QRPrinter.Master.tag = 0 then
begin
simp := inttostr(ReporteForm.quickrep1.QRPrinter.PrinterIndex);
ReporteForm.quickrep1.PrinterSettings.PrinterIndex:=GetImpresora(simp);
showmessage(simp);
        ReporteForm.quickrep1.QRPrinter.Print;
end;
end;

ecfisa 13-06-2013 08:31:10

Cita:

Empezado por jonydread (Mensaje 462153)
como puedo obtener la impresora seleccionada en el printsetup qe esta en preview del quickrep

Hola jonydread.

Para obtener la impresora actualmente seleccionada te tendría que alcanzar con:
Código Delphi [-]
...
implementation

uses Printers;

function GetCurrentPrinterName: string;
begin
  Result := '';
  if Printer.PrinterIndex <> -1 then
    Result := Printer.Printers[Printer.PrinterIndex];
end;
...
Pero en estos enlaces vas a encontrar mas opciones, tanto para obtenerla como para configurarla:
Saludos. :)

jonydread 14-06-2013 05:17:42

Muchas gracias Ecfisa y tambien a marcoszorrilla
finalmente lo logre!! #:-)#v:-)v
quedo asi
Código Delphi [-]
Function GetImpresora(Impre:String):Integer;
Var
nCont:Integer;
lSearch:Boolean;
cNewLIne:String;
begin
lSearch:=False;
cNewLine:=Chr(10)+Chr(13);

  For nCont:=0 to Printer.Printers.Count - 1 do
  //buscamos la impresora en la lista del sistema
  begin

      if Pos(impre, Printer.Printers[nCont]) <> 0 then
      begin
      lSearch:=True;
      Result:=nCont;
      Break;
      end;

  end;

  if lSearch = False then
  begin
  ShowMessage('Impresora no encontrada.'+impre+cNewLine+'Se utilizará la predeterminda.');
  Result:=-1
  end;

end;
function GetCurrentPrinterName: string;
begin
  Result := '';
  if Printer.PrinterIndex <> -1 then
    Result := Printer.Printers[Printer.PrinterIndex];
end;
procedure TPreview.ToolButton1Click(Sender: TObject);
  var
simp:string;
begin
ReporteForm.quickrep1.QRPrinter.printsetup;
if ReporteForm.quickrep1.QRPrinter.Master.tag = 0 then
begin
simp := GetCurrentPrinterName;
ReporteForm.QuickRep1.QRPrinter.PrinterIndex := getimpresora(simp);
        ReporteForm.quickrep1.QRPrinter.Print;
end;
end;


La franja horaria es GMT +2. Ahora son las 02:35:20.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi