各位高手看一下以下代码为什么一运行就出错(15分)

  • 主题发起人 主题发起人 daidaiworm
  • 开始时间 开始时间
D

daidaiworm

Unregistered / Unconfirmed
GUEST, unregistred user!
type
PDevMode=^TDevMode;
TPrinterDev = class
Driver: string;
Device: string;
Port: string;
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
do
cumentProperties(0,PrinterObject,Pchar(DevName),Devs^,Devs^,DM_OUT_BUFFER);
Devs:= DevsP;
Devs^.dmFields:=DM_PAPERSIZE;
Devs^.dmPaperSize:=DMPAPER_FANFOLD_US;
do
cumentProperties(0,PrinterObject,Pchar(DevName),Devs^,Devs^,DM_OUT_BUFFER or DM_IN_BUFFER);
finally
FreeMem(DevsP,DevSize);
end;
end;
 
在那步出错?是不是计算机中没装打印驱动?
 
Driver: string;
//
Device: string;
Port: string;
把上面的string都换成array[0..127]of char;试试
 
dmFields
dmPaperSize
从哪出来的?
 
后退
顶部