这有一段代码,你自己看吧,但愿能对你有所帮助:
//PrintDataList按照格式操纵小打印机打印数据单
//微型打印机为新容打公司产的MP宽幅打印机,以16*16点阵打印汉字,每行打印15个汉字
//上位程序调用PrintDataList,按要求填写参数即可实现打印
unit LittlePointerControl;
interface
type AxisData=array[1..5,1..4] of string;
//定义每轴数据数组类型
type PointAxisData=^AxisData;
//指向轴数据数组的指针
procedure PrintDataList(ListTitle : string;ExamTime:string;CarNumber:string;CarSpeed:string;AxisItem : integer;Data : PointAxisData;AxisTotalExcess:string;
TotalWeigh:string;TotalExcess:string;ExcessDegree:string;PunishWay:string;PunishWage:string);
implementation
var
PrintPort:textfile;
//定义打印端口为全局变量
procedure ChangeLine(LineSum : integer);
//打印纸前进LineSum行
var
i:integer;
begin
for i:=1 to LineSumdo
write(PrintPort,#13);
write(PrintPort,#10);
end;
procedure ChangeChinese(Format:integer);
//打印机转为汉字格式,汉字打印格式由Format决定
begin
write(PrintPort,#27);
write(PrintPort,#56);
write(Printport,chr(Format));
end;
procedure InitialPrinter;
//打印机初始化
begin
write(PrintPort,#27);
Write(PrintPort,#64);
write(PrintPort,#28);
write(PrintPort,#87);
write(PrintPort,#1);
end;
procedure PrintSegFlag;
begin
Write(PrintPort,'------------------------');
end;
Procedure BackLine;
//换行
begin
write(PrintPort,#13);
end;
procedure SetBlank(StrPram:string;IntOtherCode:integer);
//根据参数计算打印空格数并打出StrPram是上及模块传递的参数,IntOtherCode是本行其他打印字符的打印长度
var
IntTempLength:integer;
i:integer;
begin
IntTempLength:=length(StrPram);
IntTempLength:=IntOtherCode-IntTempLength;
for i:=1 to IntTempLengthdo
Write(PrintPort,' ');
end;
procedure PrintLine(StrTitle:string;StrPram:string);
//打印一行,StrTitle为标题,StrPram为上位模块传来的参数加上尾标
var
i:integer;
begin
write(PrintPort,StrTitle);
i:=24-Length(StrTitle);
SetBlank(StrPram,i);
write(PrintPort,StrPram);
end;
procedure PrintDataList(ListTitle : string;ExamTime : string;CarNumber:string;CarSpeed:string;AxisItem : integer;Data : PointAxisData;AxisTotalExcess:string;
TotalWeigh:string;TotalExcess:string;ExcessDegree:string;PunishWay:string;PunishWage:string);
var
i,j,w,IntTemp:integer;
StrTemp:string;
StrChineseNumber:array[1..5] of string;
//装入汉字数字
begin
StrChineseNumber[1]:='一';
StrChineseNumber[2]:='二';
StrChineseNumber[3]:='三';
StrChineseNumber[4]:='四';
StrChineseNumber[5]:='五';
assignfile(PrintPort,'LPT1');
rewrite(PrintPort);
//初始化
InitialPrinter;
ChangeLine(3);
ChangeChinese(0);
write(PrintPort,' k m');
BackLine;
write(PrintPort,'检测路线 线');
BackLine;
write(PrintPort,'检测单位');
BackLine;
write(PrintPort,'检测员签字');
BackLine;
write(PrintPort,'当事人签字');
BackLine;
PrintSegFlag;
write(PrintPort,'处罚金额');
SetBlank(PunishWage,13);
write(PrintPort,PunishWage+' 元');
write(PrintPort,'处罚方式');
SetBlank(PunishWay,16);
Write(PrintPort,PunishWay);
write(PrintPort,'超载程度');
SetBlank(ExcessDegree,16);
write(PrintPort,ExcessDegree);
PrintSegFlag;
PrintLine('总重超限',TotalExcess+' kg');
PrintLine('货车总重',TotalWeigh+' kg');
PrintLine('轴载总超限',AxisTotalExcess+' kg');
PrintSegFlag;
if (AxisItem>5) or (AxisItem<1)
then
begin
Write(PrintPort,'Axis Data Empty or Error');
BackLine;
PrintSegFlag;
end
else
begin
{for i:=1 to AxisItemdo
begin
j:=AxisItem+1-i;
PrintLine('轴 超限',Data^[j,3]+' kg');
PrintLine(StrChineseNumber[j]+' '+'荷载',Data[j,2]+' kg');
PrintLine('第 轴型', Data^[j,1]);
PrintSegFlag;
end;
}
for i:=1 to AxisItemdo
begin
IntTemp:=0;
for j:=1 to 4do
begin
for w:=1 to (j-1)*6-IntTempdo
//打印空格
write(PrintPort,' ');
write(PrintPort,Data^[AxisItem+1-i,j]);
IntTemp:=(j-1)*6+length(Data^[AxisItem+1-i,j]);
end;
if IntTemp<>24 then
BackLine;
end;
write(PrintPort,'轴轮 轴重 限载 超限');
BackLine;
PrintSegFlag;
end;
PrintLine('车速',CarSpeed+' km/h');
PrintLine('车牌号',CarNumber);
StrTemp:='';
for i:=15 to 26do
//打印时间
StrTemp:=StrTemp+ExamTime;
SetBlank(StrTemp,24);
write(PrintPort,StrTemp);
StrTemp:='';
//打印日期
for i:=1 to 14do
StrTemp:=StrTemp+ExamTime;
PrintLine('检测时间',StrTemp);
PrintSegFlag;
i:=Length(ListTitle);
StrTemp:='';
if i>24 then
begin
for i:=25 to Length(ListTitle)do
StrTemp:=StrTemp+ListTitle;
write(PrintPort,StrTemp);
BackLine;
StrTemp:='';
for i:=1 to 24do
StrTemp:=StrTemp+ListTitle;
Write(PrintPort,StrTemp);
end
else
write(PrintPort,ListTitle);
ChangeLine(5);
closefile(PrintPort);
end;