• delphi7之 fastreport本地多台打印机情况下如何选择指定打印机打印


    1.首先获取当前本地所有的打印机

    单元需要引用'Printers' 通过Printer.Printers获取打印机列表,存到配置文件或者是键值对中

    2.frxReport.PrintOptions.Printer 打印的时候用取到的打印机名称对这个属性进行赋值就可以了。

    示例代码:Unit1.pas

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, frxClass;
    
    type
      TForm1 = class(TForm)
        cbb_printers: TComboBox;
        Label1: TLabel;
        frxReport1: TfrxReport;
        btnPrint: TButton;
        procedure FormCreate(Sender: TObject);
        procedure btnPrintClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    uses
      Printers;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      cbb_printers.Items.AddStrings(Printer.Printers);
      if cbb_printers.Items.Count > 0 then
        cbb_printers.ItemIndex := 0;
    end;
    
    procedure TForm1.btnPrintClick(Sender: TObject);
    var
      print_template: string;
    begin
      if cbb_printers.Items.Count = 0 then
      begin
        ShowMessage('没有打印机');
        Exit;
      end;
    
      print_template := ExtractFilePath(ParamStr(0)) + 'print.fr3';
      if FileExists(print_template) then
      begin
        frxReport1.LoadFromFile(print_template);
        //frxReport1.DesignReport();
      end
      else
      begin
        //ShowMessage('打印模板文件:【' + print_template + '】不存在');
      end;
    
      frxReport1.PrepareReport();
      frxReport1.PrintOptions.ShowDialog:=false;
      frxReport1.PrintOptions.Printer := cbb_printers.Text;
      //frxReport1.Report.PrintOptions.Printer := cbb_printers.Text;
      frxReport1.print;
    end;
    
    end.
    

      

    Unit1.dfm

    object Form1: TForm1
      Left = 189
      Top = 220
      Width = 766
      Height = 457
      Caption = 'Form1'
      Color = clBtnFace
      Font.Charset = GB2312_CHARSET
      Font.Color = clBlue
      Font.Height = -19
      Font.Name = '微软雅黑'
      Font.Style = []
      OldCreateOrder = False
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 25
      object Label1: TLabel
        Left = 200
        Top = 96
        Width = 114
        Height = 25
        Caption = '打印机列表:'
      end
      object cbb_printers: TComboBox
        Left = 200
        Top = 144
        Width = 457
        Height = 33
        ItemHeight = 25
        TabOrder = 0
        Text = 'cbb_printers'
      end
      object btnPrint: TButton
        Left = 272
        Top = 216
        Width = 161
        Height = 57
        Caption = '打印'
        TabOrder = 1
        OnClick = btnPrintClick
      end
      object frxReport1: TfrxReport
        Version = '4.9.32'
        DotMatrixReport = False
        IniFile = 'SoftwareFast Reports'
        PreviewOptions.Buttons = [pbPrint, pbLoad, pbSave, pbExport, pbZoom, pbFind, pbOutline, pbPageSetup, pbTools, pbEdit, pbNavigator, pbExportQuick]
        PreviewOptions.Zoom = 1.000000000000000000
        PrintOptions.Printer = '预设'
        PrintOptions.PrintOnSheet = 0
        ReportOptions.CreateDate = 44085.749619872690000000
        ReportOptions.LastChange = 44085.749619872690000000
        ScriptLanguage = 'PascalScript'
        ScriptText.Strings = (
          'begin'
          ''
          'end.')
        Left = 192
        Top = 224
        Datasets = <>
        Variables = <>
        Style = <>
      end
    end
    

      

  • 相关阅读:
    数据仓库--事实表
    Oracle SQL函数pivot、unpivot转置函数实现行转列、列转行
    在Oracle中使用rank()over()排名的问题
    python 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少? 程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去 掉不满足条件的排列。(用列表推导式)
    pyhton 打印菱形
    三元运算
    Python代码书写规范
    DDT驱动
    使用 JsonPath 完成接口自动化测试中参数关联和数据验证(Python语言)
    数据类型(字典)
  • 原文地址:https://www.cnblogs.com/tc310/p/13653264.html
Copyright © 2020-2023  润新知