在程序中适时修改打印机的纸张的设置时遇到这样问题...(100分)

  • 主题发起人 主题发起人 ppl_72
  • 开始时间 开始时间
P

ppl_72

Unregistered / Unconfirmed
GUEST, unregistred user!
在uses 中已添加了printers,winspool;
procedure TForm25.SetPrinter;
var
Devs: PDevMode;
DevsP: Pointer;

DevSize: integer;

PrinterObject: THandle;

DevName: string;

begin

PrinterObject:= Printer.Handle;

DevName:= TPrinterDev(Printer.Printers.Objects[Printer.PrinterIndex]).Device;
//DevSize:=AdvancedDocumentProperties(0,PrinterObject,PChar(DevName),Devs,Devs,0);
1) DevSize:=AdvancedDocumentProperties(0,PrinterObject,PChar(DevName),Devs,Devs,0);
DevsP:=AllocMem(DevSize);

try
2) do
cumentProperties(0,PrinterObject,Pchar(DevName),DevsP,nil,DM_OUT_BUFFER);
Devs:=DevsP;

Devs^.dmFields:=DM_PAPERSIZE;

Devs^.dmPaperSize:=0;
Devs^.dmPaperLength:= 150;

Devs^.dmPaperWidth:= 100ue;

do
cumentProperties(0,PrinterObject,Pchar(DevName),DevsP,DevsP,DM_OUT_BUFFER or DM_IN_BUFFER);
finally
FreeMem(DevsP,DevSize);

end;


end;

可在编译程序时,出现这样问题:
1)[Error] khdy.pas(82): 不相容类型
2)[Error] khdy.pas(85): 不相容类型: '_devicemodeA'并且 'Pointer'
请各位大虾帮我。谢谢!
 
算了, 用下面这段吧
procedure SetPaperSize(X, Y: Integer);

// 这段代码绝对可用。单位是0.1mm
// A4时 Printer.Pagewidth:=1440; A5时 Printer.Pagewidth:=1049;
// B5时 Printer.Pagewidth:=1290; 16K时 Printer.Pagewidth:=1035;
// lq1600宽行打印机这个值宽度最大为42cm左右, 长度大约2m。
//改变devicemode结构
var
Device: array[0..255] of char;

Driver: array[0..255] of char;

Port: array[0..255] of char;

hDMode: THandle;

PDMode: PDEVMODE;

begin

Printer.PrinterIndex := Printer.PrinterIndex;

Printer.GetPrinter(Device, Driver, Port, hDMode);

if hDMode <> 0 then

begin

pDMode := GlobalLock(hDMode);

if pDMode <> nil then

begin

if (x = 0) or (y = 0) then

begin

{Set to legal}
pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;

{pDMode^.dmPaperSize := DMPAPER_LEGAL;
changed by wulianmin}
pDMode^.dmPaperSize := DMPAPER_FANFOLD_US;

end
else

begin

{Set to custom size}
pDMode^.dmFields := pDMode^.dmFields or
DM_PAPERSIZE or
DM_PAPERWIDTH or
DM_PAPERLENGTH;

pDMode^.dmPaperSize := DMPAPER_USER;

pDMode^.dmPaperWidth := x {SomeValueInTenthsOfAMillimeter};

pDMode^.dmPaperLength := y {SomeValueInTenthsOfAMillimeter};

end;


{Set the bin to use}
pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;

pDMode^.dmDefaultSource := DMBIN_MANUAL;


GlobalUnlock(hDMode);

end;


end;


Printer.PrinterIndex := Printer.PrinterIndex;

//以下开始打印
end;

 
后退
顶部