Drilon Berisha
Drilon Berisha

Reputation: 207

ShellExecute print from stream instead of file

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?

Upvotes: 2

Views: 1934

Answers (1)

David Heffernan
David Heffernan

Reputation: 612794

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.

Upvotes: 4

Related Questions