谁有超市POS 58直接打印的代码 (1分)

  • 主题发起人 主题发起人 gdljc
  • 开始时间 开始时间
G

gdljc

Unregistered / Unconfirmed
GUEST, unregistred user!
谁有超市POS 58直接打印的代码?(不用控件的。)
 
你去买一本书:POS管理系统(深圳书城有,具体名字忘记了)上面有
 
那位大侠有,可以告知吗?
 
在程序中包含printers头文件,然后直接使用printer对象,
直接对打印机输出就可以了。(printer.textout等)
 
to:guyigood
可以说得详细些吗?
 
unit fWriteRawStringToPrinter;

interface

uses
Windows,WinSpool;

function WriteRawStringToPrinter(
DocName : String;
PrinterName:String;
S:String) : Boolean;

function WriteRawStringToPrinterWithDelay(
DocName : String;
PrinterName:String;
S:String) : Boolean;

// function WriteRawStringToPrinterWithDelayByThread();

implementation

function WriteRawStringToPrinter(
DocName : String;
PrinterName:String;
S:String) : Boolean;
var
Handle: THandle;
N: DWORD;
DocInfo1: TDocInfo1;
begin
Result := True;
if not OpenPrinter(PChar(PrinterName), Handle, nil) then
begin
Result := False;
exit;
end;
with DocInfo1 do begin
pDocName := PChar(DocName);
pOutputFile := nil;
pDataType := 'RAW';
end;
StartDocPrinter(Handle, 1, @DocInfo1);
StartPagePrinter(Handle);
WritePrinter(Handle, PChar(S), Length(S), N);
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
end;

function WriteRawStringToPrinterWithDelay(
DocName : String;
PrinterName:String;
S:String) : Boolean;
var
Handle: THandle;
N: DWORD;
DocInfo1: TDocInfo1;
TmpPtr : String;
i,DelayTime : Integer;
begin
Result := True;
DelayTime := 480;
if not OpenPrinter(PChar(PrinterName), Handle, nil) then
begin
Result := False;
exit;
end;
with DocInfo1 do begin
pDocName := PChar(DocName);
pOutputFile := nil;
pDataType := 'RAW';
end;
TmpPtr := '';
for i := 1 to Length(S) do
begin
TmpPtr := TmpPtr + S;
if S = CHAR($0A) then
begin
OpenPrinter(PChar(PrinterName), Handle, nil);
StartDocPrinter(Handle, 1, @DocInfo1);
StartPagePrinter(Handle);
WritePrinter(Handle, PChar(TmpPtr), Length(TmpPtr), N);
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
sleep(DelayTime);
TmpPtr := '';
end;
end;
if S[Length(S)] <> CHAR($0A) then
begin
OpenPrinter(PChar(PrinterName), Handle, nil);
StartDocPrinter(Handle, 1, @DocInfo1);
StartPagePrinter(Handle);
WritePrinter(Handle, PChar(TmpPtr), Length(TmpPtr), N);
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
sleep(DelayTime);
TmpPtr := '';
end;
end;

end.
给分吧,我自己的程序中的过程
 
有这么复杂吗,我听说几行代码就OK了。
(超市打印的小票。)
 
你是指输入一行就打印一行吧?直接对端口写数据就OK了(LPT1,COM1,COM2).
POS 58自带有中文字库!
 
比如
销售单
日期:2002-12-20 时间:08:15 操作员:001
-------------------------------------------------
名称 单价 数量 金额
1 3 2 6
2 1 10 10
--------------------------------------------------
合计:16
 
接受答案了.
 
后退
顶部