gpt4 book ai didi

delphi - 直接向打印机发送命令的正确方法!

转载 作者:行者123 更新时间:2023-12-03 03:11:44 25 4
gpt4 key购买 nike

好的,我是这样做的:

procedure TMainWindow.btnRawPrintClick(Sender: TObject);
begin
BeginPrint;
SendStr(#27#69);
SendStr('MyData');
SendStr(#10);
EndPrint;
end;

procedure TMainWindow.SendStr(Text: String);
var
i: Integer;
data : Array of Char;
begin
for i := 1 to Length(Text) do
begin
SetLength(data,i);
data[Pred(i)] := Text[i];
end;

if (PrintRawData(printHandle,
data,
Length(data)) < 0) then begin
ShowMessage('PrintRawData Failed');
EndRawPrintPage(printHandle);
EndRawPrintJob(printHandle);
exit;
end;
end;

procedure TMainWindow.BeginPrint;
begin
printHandle := StartRawPrintJob('EPSON TM-T70 Receipt','ESDPRT001','Test Document');

if printHandle < 0 then
begin
ShowMessage('StartRawPrintJob Failed!');
exit;
end;

if (StartRawPrintPage(printHandle) < 0) then begin
ShowMessage('StartRawPrintPage Failed!');
EndRawPrintJob(printHandle);
exit;
end;
end;

procedure TMainWindow.EndPrint;
begin
if (EndRawPrintPage(printHandle) < 0) then begin
ShowMessage('EndRawPrintPage Failed');
EndRawPrintJob(printHandle);
exit;
end;

if (EndRawPrintJob(printHandle) < 0) then begin
ShowMessage('EndRawPrintJob Failed');
exit;
end;
end;

我还更改了从 here 获取的一些代码:

function PrintRawData(hPrn : THandle;
Buffer : pointer;
NumBytes : SpoolInt) : integer;
{$IFDEF WIN32}
var
BytesWritten : DWORD;
{$ENDIF}
begin
NumBytes := NumBytes * 2; //<-- I added this line
...

但是,有些问题是错误的,因为某些命令(转义序列)无法按预期工作!

最佳答案

您使用了错误的函数。使用Escape ,传递 PASSTHROUGH 标志作为第二个参数。这会将原始的、未处理的转义码直接发送到打印机。

Joe Hecht(前 Borland)多次发布了一个单元,这使得这变得更容易。我发现unit PrtRaw在这里。

关于delphi - 直接向打印机发送命令的正确方法!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5936511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com