TPrintPreview & functions

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

TPrintPreview & functions

Postby kes103 » June 18th, 2006, 2:55 pm

I am trying to learn how to use PrintPreview to Preview a Print procedure.
It appears to work fine except when I call call a function that also does some printing. The previously created image appears to go out of scope and I have to recreate it and use BeginDoc;l and EndDoc; all over again, but it won't print anything to the image. When using the printer the following:
Code: Select all
with printer do
begin
 canvas.textout() etc.; //other code
end;


but the
Code: Select all
with image do

will not work.

What do I need to do to be able to use the functions and TprintPreview?
I am using the functions to print page and table headers.
I would really like to understand how to get this to work.
Thanks in advance.
kes103
Member
Member
 
Posts: 4
Joined: June 18th, 2006, 4:11 am

Postby Kambiz » June 19th, 2006, 8:37 pm

Sorry, but I couldn't understand your problem. Could you please explain it using a complete example?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby kes103 » June 19th, 2006, 10:03 pm

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?
kes103
Member
Member
 
Posts: 4
Joined: June 18th, 2006, 4:11 am

Postby Kambiz » June 21st, 2006, 6:03 pm

What is the measurement unit?

I think the result PrintPreview page is not blank. If you zoom the page a lot, you may see some stuffs on top-left corner.

Did you get the point?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby kes103 » June 21st, 2006, 6:24 pm

Thank you.
I set the measurement unit in the main call not the function, as follows:
Code: Select all
PrintPreview1.unit := mmPixel;

Do I also need to set it in the function?
In the Object Inspector for PrintPreview1 I have the following settings:
Zoom = 54
ZoomMax = 1000
ZoomMin = 10
ZoomSavePos = True
ZoomState = zsZoomToFit
ZoomStep = 100

I dont' have a zoom procedure set up, but after minimizing and maximize several times there is nothing in the top left corner.
The PrintPreview1 is not blank, everything in the main procedure appears to be printing, however the function call just does not appear to be printing anything on PrintPreview1.
kes103
Member
Member
 
Posts: 4
Joined: June 18th, 2006, 4:11 am

Postby Kambiz » June 21st, 2006, 6:39 pm

To have a portable code, you might not use mmPixels as measurement unit.

Anyway, I think you see a blank page, because seems you create a second instance of TPrintPreview and draw on it, instead of drawing on the first instance.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby kes103 » June 21st, 2006, 6:52 pm

Well, if I try to use the first instance either it won't compile because it says "PrintPreview1 or Canvas is undefined" or I get an "EAccess Error" when I run it.
kes103
Member
Member
 
Posts: 4
Joined: June 18th, 2006, 4:11 am

Postby Kambiz » June 21st, 2006, 10:20 pm

It could be because of the owner of the form. Try to pass Application as owner.

Code: Select all
with TFormPrtPrvw.Create(Application) do
  try
    // Do initiaization here; of course it's better to do it in OnCreate of the form
    ShowModal;
  finally
    Free;
  end;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 2 guests

cron