FDevice : PChar;
FDriver : PChar;
FPort : PChar;
DeviceMode : THandle;
DevMode : PDeviceMode;
constructor TPrinterSettings.Create;
begin
inherited Create;
GetMem(FDevice, 128);
GetMem(FDriver, 128);
GetMem(FPort, 128);
FPaperSize := A4;
FPrinter := nil;
end;
function TPrinterSettings.Supported(Setting : integer) : boolean;
begin
if assigned(FPrinter) then
Supported := (DevMode^.dmFields and Setting) = Setting
else
Supported := false;
end;
procedure TPrinterSettings.SetField(aField : integer);
begin
DevMode^.dmFields := DevMode^.dmFields or aField;
end;
procedure TPrinterSettings.ApplySettings;
begin
FPrinter.GetPrinter(FDevice, FDriver, FPort, DeviceMode);
DevMode := GlobalLock(DeviceMode);
if PaperSize = Custom then
begin
SetField(dm_paperlength);
DevMode^.dmPaperLength := PaperLength;
SetField(dm_paperwidth);
DevMode^.dmPaperWidth := PaperWidth;
{$ifdef FANG}
if Supported(dm_formname) then
begin
SetField(dm_formname);
StrPCopy(DevMode^.dmFormName, PaperFormName);
end;
//fang 900327 end
{$endif}
end;
if FDuplex then
begin
SetField(dm_duplex);
DevMode^.dmDuplex := dmdup_horizontal;
end;
if Supported(dm_PaperSize) and (PaperSize <> Default) then
begin
SetField(dm_papersize);
{$ifdef FANG}
if GetVersion() < $80000000 then
begin
if GetPrnPaperSize(FDevice, PaperFormName, iPaperSize) then
DevMode^.dmPaperSize := iPaperSize
else
DevMode^.dmPaperSize := cQRPaperTranslate[PaperSize];
end
else
{$endif}
DevMode^.dmPaperSize := cQRPaperTranslate[PaperSize];
end;
SetField(dm_copies);
DevMode^.dmCopies := FCopies;
SetField(dm_defaultsource);
DevMode^.dmDefaultSource := (DevMode^.dmDefaultSource and 256) or cQRBinTranslate[OutputBin];
SetField(dm_orientation);
if Orientation=poPortrait then
DevMode^.dmOrientation := dmorient_portrait
else
DevMode^.dmOrientation := dmorient_landscape;
FPrinter.SetPrinter(FDevice, FDriver, FPort, DeviceMode);
GlobalUnlock(DeviceMode);
end;