* * *

Author Topic: Passing a filename for a Printer  (Read 309 times)

J-G

  • Sr. Member
  • ****
  • Posts: 435
Passing a filename for a Printer
« on: October 13, 2017, 03:52:10 pm »
My default 'Printer' is a .PDF creator and whilst I have no problem creating documents I have to manually specify the filename once the print-dialog appears.

I would prefer to generate the filename within the 'Print' routine so that it appears in the print-dialogue ready for minor adjustment should be appropriate.

TPrinter has a property .Filename which I can set either before or after 'Finally' - viz:
Code: Pascal  [Select]
  1. begin
  2.     with Printer do
  3.       try
  4.         BeginDoc;
  5.         [...]
  6.         FileName:=IntToStr(DataYear)+'-RAW.PDF';
  7.       finally
  8. //  could be here         FileName:=IntToStr(DataYear)+'-RAW.PDF';
  9.         EndDoc;
  10.       end;
  11. end;
  12.  

...but as yet it doesn't appear in the dialogue.

Am I asking too much? 
FPC 3.0.0  Lazarus 1.6  Win 7 Ult 64

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 648
Re: Passing a filename for a Printer
« Reply #1 on: October 13, 2017, 11:24:37 pm »
hello,
use the Title property (without .pdf) example :
Code: Pascal  [Select]
  1. begin
  2.     with Printer do
  3.       try
  4.         BeginDoc;
  5.         [...]
  6.         Title:=IntToStr(DataYear)+'-RAW';
  7.       finally
  8. //  could be here         FileName:=IntToStr(DataYear)+'-RAW.PDF';
  9.         EndDoc;
  10.       end;
  11. end;
  12.  

Friendly, J.P

J-G

  • Sr. Member
  • ****
  • Posts: 435
Re: Passing a filename for a Printer
« Reply #2 on: October 14, 2017, 02:14:23 am »
use the Title property (without .pdf)
Fantastic JP - Thanks  -  works exactly as I hoped.

I ought to have looked deeper into the properties but 'Filename' was the most obvious (to my mind anyway!)

Why don't we have a 'smiley' with applause ? 
FPC 3.0.0  Lazarus 1.6  Win 7 Ult 64

J-G

  • Sr. Member
  • ****
  • Posts: 435
Re: Passing a filename for a Printer
« Reply #3 on: October 14, 2017, 09:58:44 am »
Maybe I spoke too soon  :(

Yes, it put the filename (Title) in the dialogue at my first test, but this morning I added the code to the rest of the 'Print' procedures and find that the first 'print' request shows a blank and subsequent requests show the previous filename  %)   
-  Like Ronnie Cobet on Mastermind answering the question before the one being asked  :D  (some of you may have seen that 2 Ronnies Sketch).

I have some commitments this morning so I'll investigate further shortly and report back.
FPC 3.0.0  Lazarus 1.6  Win 7 Ult 64

J-G

  • Sr. Member
  • ****
  • Posts: 435
Re: Passing a filename for a Printer
« Reply #4 on: October 14, 2017, 01:54:16 pm »
Sorted !

The 'Title' needs to be assigned 'outside' or 'prior' to the 'Try-Finally' block ...
Code: Pascal  [Select]
  1. begin
  2.     Printer.Title:= IntToStr(DataYear)+'-RAW';
  3.     with Printer do
  4.       try
  5.         BeginDoc;
  6.          [...]
  7.       finally
  8.         EndDoc;
  9.       end;
  10.   end;
  11.  
As it happens, in all of my [Print] routines the title will be known at this stage, but there could be a time when it might need to be evaluated during the print run. Does anyone have an opinion about how this might be achieved?
FPC 3.0.0  Lazarus 1.6  Win 7 Ult 64

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus