The code below assumes that a PrintJob is already open.
PEGetPrintOptions
uses CRDelphi;
{Stringlists to store the Section Format information}
var
sSuppress,
sNewPageBefore,
sNewPageAfter,
sKeepTogether,
sSuppressBlankSection,
sResetPageNAfter,
sPrintAtBottomOfPage,
sUnderlaySection,
sBackgroundColor,
sFreeFormPlacement : TStringList;
procedure GetSectionFormat;
var
SecOpt : PESectionOptions;
nSections,
nSection : smallint;
nCode : smallint;
begin
SecOpt.structSize := SizeOf(PESectionOptions);
{Get the # of Sections in the Report}
nSections := PEGetNSections(PrintJob);
if (nSections = -1 ) then
{Do Error Handler};
{Create storage StringLists}
sSuppress := TStringList.Create;
sNewPageBefore := TStringList.Create;
sNewPageAfter := TStringList.Create;
sKeepTogether := TStringList.Create;
sSuppressBlankSection := TStringList.Create;
sResetPageNAfter := TStringList.Create;
sPrintAtBottomOfPage := TStringList.Create;
sUnderlaySection := TStringList.Create;
sFreeFormPlacement := TStringList.Create;
sBackgroundColor := TStringList.Create;
{Loop through the Sections}
for nSection := 0 to (nSections - 1) do
begin
nCode := PEGetSectionCode(PrintJob, nSection);
if not PEGetSectionFormat(PrintJob, nCode, SecOpt) then
{Do Error Handler};
case SecOpt.visible of
0: sSuppress.Add('1');
1: sSuppress.Add('0');
end;
sNewPageBefore.Add(IntToStr(SecOpt.newPageBefore));
sNewPageAfter.Add(IntToStr(SecOpt.newPageAfter));
sKeepTogether.Add(IntToStr(SecOpt.keepTogether));
sSuppressBlankSection.Add(IntToStr(SecOpt.suppressBlankSection));
sResetPageNAfter.Add(IntToStr(SecOpt.resetPageNAfter));
sPrintAtBottomOfPage.Add(IntToStr(SecOpt.printAtBottomOfPage));
sUnderlaySection.Add(IntToStr(SecOpt.underlaySection));
sFreeFormPlacement.Add(IntToStr(SecOpt.freeFormPlacement));
{Background Color}
if SecOpt.backgroundColor = PE_NO_COLOR then
sBackgroundColor.Add('-1 ')
else
sBackgroundColor.Add(IntToStr(SecOpt.backgroundColor));
end;
end;
procedure SetSectionFormat;
var
SecOpt : PESectionOptions;
nSection,
nSections
nCode : smallint;
nTmp1, nTmp2 : smallint;
Changed : boolean;
nColor1, nColor2 : integer;
begin
SecOpt.structSize := SizeOf(PESectionOptions);
{Get the # of Sections in the Report}
nSections := PEGetNSections(PrintJob);
if (nSections = -1 ) then
{Do Error Handler};
{Loop through the Sections}
for nSection := 0 to (nSections - 1) do
begin
Changed := False;
nCode := PEGetSectionCode(PrintJob, nSection);
if not PEGetSectionFormat(PrintJob, nCode, SecOpt) then
{Do Error Handler};
{Visible}
nTmp1 := SecOpt.visible;
try
case StrToInt(sSuppress[nSection]) of
0: nTmp2 := 1; {translate "Suppress" to "Visible" by inverting}
1: nTmp2 := 0;
2: nTmp2 := 2;
end;
except
nTmp2 := 2;
end;
if nTmp2 < 2 then
begin
if nTmp1 <> nTmp2 then
begin
SecOpt.visible := nTmp2;
Changed := True;
end;
end;
{NewPageBefore}
nTmp1 := SecOpt.newPageBefore;
try
nTmp2 := StrToInt(sNewPageBefore[nSection]);
except
nTmp2 := 2;
end;
if nTmp2 < 2 then
begin
if nTmp1 <> nTmp2 then
begin
SecOpt.newPageBefore := nTmp2;
Changed := True;
end;
end;
{NewPageAfter}
nTmp1 := SecOpt.newPageAfter;
try
nTmp2 := StrToInt(sNewPageAfter[nSection]);
except
nTmp2 := 2;
end;
if nTmp2 < 2 then
begin
if nTmp1 <> nTmp2 then
begin
SecOpt.newPageAfter := nTmp2;
Changed := True;
end;
end;
{KeepTogether}
nTmp1 := SecOpt.keepTogether;
try
nTmp2 := StrToInt(sKeepTogether[nSection]);
except
nTmp2 := 2;
end;
if nTmp2 < 2 then
begin
if nTmp1 <> nTmp2 then
begin
SecOpt.keepTogether := nTmp2;
Changed := True;
end;
end;
{SuppressBlankSection}
nTmp1 := SecOpt.suppressBlankSection;
try
nTmp2 := StrToInt(sSuppressBlankSection[nSection]);
except
nTmp2 := 2;
end;
if nTmp2 < 2 then
begin
if nTmp1 <> nTmp2 then
begin
SecOpt.suppressBlankSection := nTmp2;
Changed := True;
end;
end;
{ResetPageNAfter}
nTmp1 := SecOpt.resetPageNAfter;
try
nTmp2 := StrToInt(sResetPageNAfter[nSection]);
except
nTmp2 := 2;
end;
if nTmp2 < 2 then
begin
if nTmp1 <> nTmp2 then
begin
SecOpt.resetPageNAfter := nTmp2;
Changed := True;
end;
end;
{PrintAtBottomOfPage}
nTmp1 := SecOpt.printAtBottomOfPage;
try
nTmp2 := StrToInt(sPrintAtBottomOfPage[nSection]);
except
nTmp2 := 2;
end;
if nTmp2 < 2 then
begin
if nTmp1 <> nTmp2 then
begin
SecOpt.printAtBottomOfPage := nTmp2;
Changed := True;
end;
end;
{UnderlaySection}
nTmp1 := SecOpt.underlaySection;
try
nTmp2 := StrToInt(sUnderlaySection[nSection]);
except
nTmp2 := 2;
end;
if nTmp2 < 2 then
begin
if nTmp1 <> nTmp2 then
begin
SecOpt.underlaySection := nTmp2;
Changed := True;
end;
end;
{FreeFormPlacement}
nTmp1 := SecOpt.freeFormPlacement;
try
nTmp2 := StrToInt(sFreeFormPlacement[nSection]);
except
nTmp2 := 2;
end;
if nTmp2 < 2 then
begin
if nTmp1 <> nTmp2 then
begin
SecOpt.freeFormPlacement := nTmp2;
Changed := True;
end;
end;
{BackgroundColor}
if SecOpt.backgroundColor = PE_NO_COLOR then
nColor1 := -1
else
nColor1 := SecOpt.backgroundColor;
try
nColor2 := StrToInt(sBackgroundColor[nSection]);
except
nColor2 := PE_UNCHANGED_COLOR;
end;
if nColor2 <> PE_UNCHANGED_COLOR then
begin
if nColor1 <> nColor2 then
begin
SecOpt.backgroundColor := nColor2;
Changed := True;
end;
end;
{Send SectionFormat to Report}
if Changed then
begin
if not PESetSectionFormat(PrintJob, nCode, SecOpt) then
{Do Error Handler};
end;
end;
{Free storage StringLists}
sSuppress.Free;
sNewPageBefore.Free;
sNewPageAfter.Free;
sKeepTogether.Free;
sSuppressBlankSection.Free;
sResetPageNAfter.Free;
sPrintAtBottomOfPage.Free;
sUnderlaySection.Free;
sFreeFormPlacement.Free;
sBackgroundColor.Free;
end;
| Seagate Software IMG Holdings, Inc. http://www.seagatesoftware.com Support services: http://support.seagatesoftware.com |