Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print a File

Status
Not open for further replies.

gforrest

Programmer
Apr 26, 2000
39
CA
Is there a simple way to print a text file from Delphi? I have a file in the same directory as my code and I simply want to send it to print.

Thanks
 
gforrest,

This should get you started:

Code:
procedure TForm1.Button1Click(Sender: TObject);
var
   strFilename : String;
   strErrorMsg : String;
begin

   strFilename := edit1.text;
   if not fileExists( strFilename )
   then
      begin
         beep();
         strErrorMsg := 'Can''t find a file named "' +
                        strFilename + '"' + #10#10 +
                        'Please check your filename. ';
         application.MessageBox( pChar( strErrorMsg ),
            'Can''t Print',  MB_ICONSTOP + MB_OK );
      end
   else
      with tRichEdit.createParented( self.Handle ) do
      try
         lines.loadFromFile( strFileName );
         print( 'Printout caption' );
      finally
         free;
      end;
end;

Note that this works under Delphi 5.01. If you're using an older version that this doesn't work under, consider this TI from Borland's site:


Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top