[Error] Unit1.pas(47): Incompatible types: '_devicemodeA' and 'PDevMode'错误(0分)

  • 主题发起人 主题发起人 hooyu
  • 开始时间 开始时间
H

hooyu

Unregistered / Unconfirmed
GUEST, unregistred user!
我在编译时,提示以上错误,请高手指点一二。谢谢

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,Printers,WinSpool;

type
PDevMode=^TDevMode;
TPrinterDev = class
Driver: string;
Device: string;
Port: string;
end;

TForm1 = class(TForm)
Button1: TButton;
procedure SetPrinter;


private
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;


implementation

{$R *.DFM}

procedure TForm1.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:=DocumentProperties(0,PrinterObject,PChar(DevName),Devs,Devs,0);
DevsP:=AllocMem(DevSize);
try
DocumentProperties(0,PrinterObject,Pchar(DevName),DevsP,nil,DM_OUT_BUFFER);
Devs:=DevsP;
Devs^.dmFields:=DM_PAPERSIZE;
Devs^.dmPaperSize:=DMPAPER_FANFOLD_US; //在这里换成你想要的纸张, 下面的是自定义纸张
// if use USER_DEFINE paper then
// this line change to
// Devs^.dmFields:= DM_PAPERSIZE or DM_PAPERLENGTH or DM_PAPERWIDTH;

// Devs^.dmPaperSize:=0;
// Devs^.dmPaperLength:= ur defined paper length value;
// Devs^.dmPaperWidth:= ur defined paper width value;
DocumentProperties(0,PrinterObject,Pchar(DevName),DevsP,DevsP,DM_OUT_BUFFER or DM_IN_BUFFER);
finally
FreeMem(DevsP,DevSize);
end;
end;

end.


 
看winspool单元的关于DocumentProperties说明:
{$EXTERNALSYM DocumentProperties}
function DocumentProperties(hWnd: HWND; hPrinter: THandle; pDeviceName: PChar;
const pDevModeOutput: TDeviceMode; var pDevModeInput: TDeviceMode;
fMode: DWORD): Longint; stdcall;
你用指针作参数当然不匹配了!!
 
你说得对,可是我对打印API不很明白,未知那位高手指点一二。
 
接受答案了.
 
后退
顶部