We are encountering a Delphi printing problem when we try to use a
modified DevMode.
When we save and reset the DevMode, the Printer.setPrinter method
sends only a few hundred bytes to the printer.
What we did were,
1. Call Printer Properties Dialog. Do some changes with Printer
Property dialog.
2. Save the modified DevMode in PrnLst (TStringList) as a object.
3. Reset the Saved DevMode again to the selected printer when press
the PrintOK button.
We used the following source code to implement this:
///////////////////////////////////////////////////////////
Private
PrnLst : TStrings;
procedure TFrmPrnDld.ButtonPropertiesClick(Sender: TObject);
var
ADevice, ADriver, APort: array[0..MAX_PATH] of Char;
hDevMode :THandle;
ADevMode :PDeviceMode;
hDevModeOrg :THandle;
begin
Printer().GetPrinter(ADevice, ADriver, APort, hDevModeOrg);
hDevMode := copyGlobal(hDevModeOrg);
ADevMode := GlobalLock(hDevMode);
//Copies
ADevMode^.dmCopies := Trunc(SpinEdCollate.Editor.value);
try
if (DocumentProperties(Self.Handle, 0, ADevice, ADevMode^,
ADevMode^,
DM_IN_BUFFER or DM_IN_PROMPT or DM_OUT_BUFFER) <> IDOK) then
exit;
storeDevMode(PrinterCombo.ItemIndex, ADevMode, GlobalSize
(hDevMode));
finally
GlobalUnlock(hDevMode);
GlobalFree(hDevMode);
end;
end;
procedure TFrmPrnDld.okButClick(Sender: TObject);
begin
getPrinter(PrinterCombo.ItemIndex);
ModalResult := mrOk;
end;
procedure TFrmPrnDld.storeDevMode(PrinterIndex :integer;
ADevMode :PDeviceMode; ADevSize :integer);
var
hTemp :THandle;
pdmTemp :PDeviceMode;
begin
if (PrinterIndex = -1) then exit;
if (THandle(PrnLst.Objects[PrinterIndex]) <> 0) then begin
hTemp := THandle(PrnLst.Objects[PrinterIndex]);
GlobalFree(hTemp);
end;
hTemp := GlobalAlloc(GHND, ADevSize);
pdmTemp := GlobalLock(hTemp);
try
System.Move(ADevMode^, pdmTemp^, ADevSize);
finally
GlobalUnlock(hTemp);
end;
PrnLst.Objects[PrinterIndex] := TObject(hTemp);
end;
function TFrmPrnDld.getPrinter(PrinterIndex :integer) :boolean;
var
hTemp :THandle;
begin
Result := false;
if (PrinterIndex = -1) then exit;
Printer().PrinterIndex := PrinterIndex;
Printer().GetPrinter(ADevice, ADriver, APort, ADeviceMode);
//Get previous printer setting
hTemp := 0;
if (PrnLst.Objects[PrinterIndex] <> nil) then begin
hTemp := copyGlobal(THandle(PrnLst.Objects[PrinterIndex]));
end;
//Some printers may fail the above GetPrinter
Printer().SetPrinter(ADevice, ADriver, APort, hTemp);
Printer().GetPrinter(ADevice, ADriver, APort, ADeviceMode);
Result := true;
end;
function TFrmPrnDld.copyGlobal(hSource :HGLOBAL) :HGLOBAL;
var
intSize :integer;
pSrc, pDest :PByte;
begin
Result := 0;
if (hSource = 0) then exit;
pSrc := GlobalLock(hSource);
try
intSize := GlobalSize(hSource);
Result := GlobalAlloc(GHND, intSize);
pDest := GlobalLock(Result);
try
System.Move(pSrc^, pDest^, intSize);
finally
GlobalUnlock(Result);
end;
finally
GlobalUnlock(hSource);
end;
end;
///////////////////////////////////////////////////////////////////
This problem can be seen only for certain types of printers such
as "Cannon LBP 740".
Did any one encountered a similar problem? Please help.
(Delphi 5)
Thank you,
pri_sama.
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/