在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;
可是,为什么控制不了呢?希望各位高手赐教!
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;
可是,为什么控制不了呢?希望各位高手赐教!
解决方案 »
- 请问如何将程序中所有的窗体和单元文件的源码保存到文本文件中?
- 急,dxDBTreeView控件的一个非常重大的隐患
- SPCOMM串口通信的问题,在线急等!100分送上!
- 怎么给treeview的节点加上checkbox?
- 如何自动注册服务器程序?
- 请问我如何才能让batchmove只更新我指定的部分字段?
- 多个线程同时操作一个文本文件会出错
- 什么是"模拟态对话框"?
- 如何在memo中查找到匹配的字符串,并选中他
- 在dephi5.0下怎样存取text,为什么我在在保存sql的Text字段时,总是提示我'Non-blob column in table required to perform operation' 为什么?请各位提示一下??
- 二维字符串数组和列表
- 如何发送打印机控制命令?
能不能详细一些,最好给个例子。谢谢!