OK, well I have a proceudure called PreviewPrintProj inside a unit.
There is also another form/unit with the PrintPreview1 image on it called SamplePrintPreview.
The PreviewPrintProj procedure has some functions that print page headers.
Print previewing is started likes so (after prleminary declarations and the function and some procedure definitions):
- Code: Select all
//main procedure here
begin
with SamplePrintPreview.TFormPrtPrvw.Create(FormPrtPrvw) do
try
with PrintPreview1 do
begin
BeginDoc;
CurVPos := PrntHdr(); { CurVPos is a global integer declared at beginning of procedure}
EndDoc;
end;
ShowModal;
finally
free;
end;
end;
end;
Everything above except for some setting issues I think prints to the image fine.
PntHdr function is like this:
- Code: Select all
//
function PrintHdr() :Integer;
const
CMP = 'Whoever'; //Company Licensed to
var
Proj :String[50]; //Project Name
ProjNo :String[25]; //Project Number
CurVPos :Integer; //Current vertical position
//
begin
// with Printer do {used when printing}
// with PrintPreview.TFormPrtPrvw do
// with PrintPreview.FormPrtPrvw.PrintPreview1 do
// With FormPrtPrvw.PrintPreview1 do
// with SamplePrintPreview.FormPrtPrvw.PrintPreview1 do
// with SamplePrintPreview.TFormPrtPrvw(TFormPrtPrvw).PrintPreview1 do
{I've tried every which way I can think of here}
with SamplePrintPreview.TFormPrtPrvw.Create(FormPrtPrvw).PrintPreview1 do
begin
BeginDoc; {not needed when using Printer}
Canvas.Font.Height := 20;
Canvas.TextOut(10,90,'Program Name: Copyright © 1991, 2006 by Me, P.E.');
CurVPos := 60 + 90;
Canvas.TextOut(10,CurVPos,'Program Description Header.');
CurVPos := CurVPos + 60;
Canvas.TextOut(10,CurVPos,'Licensed to: ' + CMP);
CurVPos := CurVPos + 55;
Proj := form1.Edt_ProjName.Text;
ProjNo := form1.Edt_ProjNo.Text;
Canvas.TextOut(100,CurVPos,'Project: '+ Proj);
Canvas.TextOut(180,CurVPos,'Proj. No.:'+ ProjNo);
CurVPos :=CurVPos +(2*55);
//Print Demonstration copy across Demo Printouts - comment these out for licnesed copies
//{
Canvas.Brush.Style := bsClear;
Canvas.Font.Height := 200;
AngleTextOut(Canvas,45,90,200,'DEMONSTRATION COPY');
Canvas.Font.Height := 20;
//}
//end print demonstration copy
// Show;
EndDoc; {not needed with printer}
end;
// show;
Result := CurVPos;
end; //end function PrintHdr
//
Nothing in the the function will print. I left out the procedure AngleTextOut.
The above is very much like printing to the printer. I simply tried substituing the PrintPreview1 image for the printer.
I have put the separate form in the uses statment(s).
Nothing will work. Although the function is defined before the main part of the procedure (should make it global right?) it won't print. Seems to be out of scope.
What should I do?