You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Delphi 11.3调试模式下打印机报错问题求助

Delphi 11.3调试模式下打印报错(独立运行正常)

问题概述

安装HP Office Jet Pro 9010新打印机并移除所有旧打印机后,仅在Delphi 11.3调试模式下打印出现异常:

  • 选择默认打印机时,提示:

    Printer selected is not valid

  • 切换选择其他打印机时,提示:

    Operation not supported on selected printer
    程序脱离IDE独立运行时一切正常,卸载重装打印机、清理注册表、重启电脑均无法解决问题,且Delphi 12.3/13版本无此异常。

环境信息

  • IDE版本:Delphi 11.3 Alexandria
  • 操作系统:Windows 11 Pro
  • 目标打印机:HP Office Jet Pro 9010

测试代码

unit Main;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.printers;

type
  TForm1 = class(TForm)
    Button1: TButton;
    PrintDialog1: TPrintDialog;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if PrintDialog1.Execute then
  begin
    Printer.BeginDoc; // 报错位置
    Printer.EndDoc;
  end;
end;

end.

解决方案

针对Delphi 11.3的专属修复方案:

  1. 重置IDE调试配置
    关闭Delphi,删除%APPDATA%\Embarcadero\BDS\21.0目录下的所有配置文件(建议先备份),重启IDE后重新配置调试环境,清除旧打印机缓存信息。
  2. 显式指定打印机并刷新状态
    在调用BeginDoc前手动绑定选中的打印机并刷新状态,避免调试模式下的驱动检测异常:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if PrintDialog1.Execute then
      begin
        Printer.PrinterIndex := PrintDialog1.PrinterIndex;
        Printer.Refresh; // 强制刷新打印机状态
        Printer.BeginDoc;
        Printer.EndDoc;
      end;
    end;
    
  3. 安装IDE最新补丁
    检查并安装Embarcadero发布的Delphi 11.3后续官方补丁,此类打印调试逻辑问题通常会在补丁中修复。
  4. 禁用调试器打印机挂钩
    打开IDE的Tools > Options > Debugger > Emulation,找到与打印机相关的调试挂钩选项并禁用,避免IDE调试时干扰打印机驱动交互。

内容的提问来源于stack exchange,提问作者Daniele

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 00:04:56