我想用delphi寫一個在標簽上面打印2列流水號的程序,程序內容如下面,但是
程序執行時出現"Printer selected is not valid."的錯誤提示,各位大俠能否幫我看看是什麼問題?
procedure TForm1.Button1Click(Sender: TObject);
var
seq1: Integer;
seq2: Integer;
i: Integer;
j: Integer;
l: Integer;
Device:Array[0..cchDeviceName-1] of Char;
Driver:Array[0..(MAX_PATH-1)] of Char;
Port:Array[0..32] of Char;
hDMode:THandle;
pDMode
DevMode;
begin
Printer.GetPrinter(Device,Driver,Port,hDMode);
if hDMode<>0 then
begin
pDMode:=GlobalLock(hDMode);
if pDMode<>nil then
begin
pDMode^.dmPaperSize:= 256;
pDMode^.dmPaperLength:= 40;
pDMode^.dmPaperWidth:= 10;
pDMode^.dmFields:=pDMode^.dmFields or DM_PAPERSIZE;
pDMode^.dmFields:=pDMode^.dmFields or DM_PAPERLENGTH;
pDMode^.dmFields:=pDMode^.dmFields or DM_PAPERWIDTH;
GlobalUnLock(hDMode);
end;
end;
seq1:=StrToInt(Form1.Edit1.Text);
seq2:=StrToInt(Form1.Edit2.Text);
//read the start number and the end number
Printer.begin
Doc;
Printer.Canvas.Font.Name:='Arial Black';
Printer.canvas.Font.size:=18;
Printer.Canvas.Font.Style:=[fsBold];
//set font
l:=((seq2 - seq1) div 2)+1;
j:= 1;
for i:=1 to ldo
begin
Printer.Canvas.TextOut(1,j,IntToStr(seq1));
Printer.Canvas.TextOut(150,j,IntToStr(seq1+1));
// print
seq1:=seq1+2;
j:=j+150;
Printer.NewPage;
//newpage
end;
Printer.EndDoc;
end;