2

With this

ShellExecute(Handle, 'print', PChar(ExtractFilePath(ParamStr(0))+'Test.txt'), 
   nil, nil, SW_HIDE);

It is possible to print out files.

Is there a way I can use a TStream instead of a file so that I can print directly from my stream?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Drilon Berisha
  • 207
  • 1
  • 2
  • 14

1 Answers1

4

No, you can't use ShellExecute to print from a Delphi stream. The call to ShellExecute will result in a different process performing the printing operation. And that different process cannot see your Delphi stream.

A couple of options spring to mind:

  1. Save the stream to a temporary file, and print that using ShellExecute.
  2. Print the text directly from Delphi. One quick and dirty method would be to add the text to a TRichEdit and call its Print method. Andreas Rejbrand has more details here.
Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490