PrintPreview - TPreview. Copyright Richard Vowles, August 1995 (r.vowles@auckland.ac.nz) Try my home page on http://comu2.auckland.ac.nz/~root/ This is Version 1.0, released August 23rd, 1995. Introduction ------------ Delphi doesn't come with a Print Preview component, which is a bit of a pest as the printer object is expensive (both in time and in cost of materials) to experiment with, the user can't see what is going to come out, and the programmer spends hours of time just figuring out where that line was supposed to go. I needed one, ReportSmith is so slow and big that it is useless, and it would be a very smart report writer that could do what I needed it to do (which is primarily price lists with all sorts of extra configurable features). So I wrote a Print Preview component, and I assure you, it is no easy task! (Well, it was primarily a task of understanding what is actually going on underneath). The Details ----------- I started with the premise that the main point of the component was that if you said Preview=True then it would pop up a form which would show you what would appear on the printer, which you could scale as you liked it. If you said Preview=False then the output would go to the printer (after asking the user what they actually wanted to print). There was obviously a need to provide a Canvas, but I needed that Canvas to work in TWIPS (1 inch = 1440 twips), not pixels as they are not device independant. So there are two things you need to know about: TPREVIEW which is the component, and TPREVIEWCANVAS which is the Canvas that you draw with. Using It -------- Here is a most typical code scenario. I use Preview1 in two different places on the same form, each with a different report, so I need to assign OnPaint each time I use it. You won't have to do this if you just use one TPREVIEW, one form: Preview1.OnPaint := Preview1Paint; Preview1.PreviewMode := True; Preview1.PageCount := 1; Preview1.BeginDoc; wantToPrint := Preview1.Print; Preview1.EndDoc; if wantToPrint then begin Preview1.PreviewMode := False; if Preview1.BeginDoc then begin Preview1.Print; Preview1.EndDoc; end; end; The ACTUAL PageCount is set in my Preview1Paint routine, as mentioned above. The sample application (PRT) also includes very basic info on how to use the component. The Essential Bits ------------------ This work is copyrighted by Richard Vowles, r.vowles@auckland.ac.nz. You can use it as you like it, you can publish as part of shareware collections and so forth. What you cannot do is take it am claim it as your own and/or sell it as part of a collection of your own work. Oh, and you must leave this entire text at the top of the unit declaration. Oh, and any bugs, please send them to me at the above Internet address. Now, I was going to make this postcardware, but my wife insisted that I ask people to send me a donation for using it instead! Ok, so I would like $US15 (unless you are in NZ, in which case $NZ15 as it is easier). You can send it in currency (if you trust your postee) or bank cheque. Consider this shareware. The address to send to is Richard Vowles Micro Utilities Ltd PO BOX 100 214 North Shore Mail Center Auckland New Zealand If you send your email address along with it, I'll let you know any time I send an update version. In fact, I'll email one out to you! Richard