在Delphi中如何控制打印份数?(在线等待!)
在Delphi中如何控制打印份数?我的源代码如下:
var
App,Item:OleVariant;
Fn:String;
ADevice,ADriver,APort:Array[0..255] Of Char;
DeviceHandle:THandle;
DevMode:PDeviceMode;
Printer:TPrinter;
begin
If PrintDialog.Execute then
begin
Printer:=TPrinter.Create;
Fn:=ExtractFilePath(Application.ExeName);
Fn:=Fn+'Doc\temp.doc';
app:=CreateOleObject('Word.Application');
app.Application.Options.CreateBackup:=False;
App.Application.Options.SaveNormalPrompt:=False;
App.Application.Options.SavePropertiesPrompt:=False;
Item:=1;
If (Not dm.Data.Prints.FieldByName('PrintImage').IsNull) and (dm.Data.Pacts.FieldByName('Act').AsBoolean) then
begin //盖章并打印合同
TBlobField(dm.Data.Pacts.FieldByName('Pact')).SaveToFile(Fn);
Sleep(50);
app.application.documents.open(Fn);
ClipBoard.Clear;
Photo.CopyToClipboard;
app.Application.Documents.Item(Item).Sentences.Last.Paste;
end
Else
begin
ShowMessage('不存在指定的章或者该合同是无效合同!');
Exit;
end;
Printer.GetPrinter(ADevice,ADriver,APort,DeviceHandle);
If DeviceHandle=0 then
begin
Printer.PrinterIndex:=Printer.PrinterIndex;
Printer.GetPrinter(ADevice,ADriver,APort,DeviceHandle);
end;
If DeviceHandle=0 then
Raise Exception.Create('不能初始化打印驱动程序,打印失败!')
Else
begin
DevMode:=GlobalLock(DeviceHandle);
With DevMode^ do
begin
dmFields:=dmFields Or DM_COPIES;
dmCopies:=PrintDialog.Copies;
end;
App.Application.Documents.Item(Item).PrintOut;
end;
Sleep(9600);
ClipBoard.Clear;
App.Application.Documents.Item(Item).Saved:=True;
App.Quit;
DeleteFile(Fn);
GlobalUnlock(DevMode);
end;
end;
可是,为什么控制不了呢?希望各位高手赐教!