Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 11-14-2002, 07:15 AM
BlindReaper BlindReaper is offline
Member
 
Join Date: Nov 2002
Posts: 32
Default Printing a text file from Delphi

Hi all,

I am quite new to delphi and was wondering how i can get delphi to print a text file?

Thanks in advance,
Paul

btw, good forums!
Reply With Quote
  #2  
Old 11-14-2002, 07:33 AM
simes simes is offline
Senior Member
 
Join Date: Jan 2002
Posts: 2,327
Default RE: Printing a text file from Delphi

Use the ShellExecute function.
uses
ShellApi, ShlObj;

procedure TForm1.Button1Click(Sender: TObject);
var
filename: string;
begin
filename := 'z.txt';
ShellExecute(handle, 'print', pchar(Filename), nil, nil, SW_NORMAL);
end;


Please click accept if this helps

Simon
SadMan Software
http://www.simes.clara.co.uk
Reply With Quote
  #3  
Old 11-14-2002, 07:39 AM
BlindReaper BlindReaper is offline
Member
 
Join Date: Nov 2002
Posts: 32
Default RE: Printing a text file from Delphi

didn't work!

HELP!
Reply With Quote
  #4  
Old 11-14-2002, 07:46 AM
simes simes is offline
Senior Member
 
Join Date: Jan 2002
Posts: 2,327
Default RE: Printing a text file from Delphi

Works for me with D5 under Win2K. The system opens notepad (or whatever application is associated with the filetype) and tells it to print.

If there's no associated application, you can do it yourself. Open the file and render the text it contains to a printer canvas.

Please click accept if this helps

Simon
SadMan Software
http://www.simes.clara.co.uk
Reply With Quote
  #5  
Old 11-14-2002, 12:31 PM
BlindReaper BlindReaper is offline
Member
 
Join Date: Nov 2002
Posts: 32
Default RE: Printing a text file from Delphi

still no working

(Using D7:Enterprise on WinXP Home)
Reply With Quote
  #6  
Old 11-14-2002, 01:05 PM
simes simes is offline
Senior Member
 
Join Date: Jan 2002
Posts: 2,327
Default RE: Printing a text file from Delphi

What is the filetype of the text file? If you double-click the file in Explorer, what application opens?

Did you try the code sample with a simple .TXT file?

Please click accept if this helps

Simon
SadMan Software
http://www.simes.clara.co.uk
Reply With Quote
  #7  
Old 11-14-2002, 01:39 PM
BlindReaper BlindReaper is offline
Member
 
Join Date: Nov 2002
Posts: 32
Default RE: Printing a text file from Delphi

it is a .txt file

if u use MSN Messenger, contact me on paul_bidwell@hotmail.com
Reply With Quote
  #8  
Old 11-14-2002, 01:47 PM
simes simes is offline
Senior Member
 
Join Date: Jan 2002
Posts: 2,327
Default RE: Printing a text file from Delphi

Most strange. It worked for me.
Sorry, don't use it.

Please click accept if this helps

Simon
SadMan Software
http://www.simes.clara.co.uk
Reply With Quote
  #9  
Old 11-14-2002, 06:20 PM
johnjces johnjces is offline
Senior Member
 
Join Date: Oct 2001
Posts: 444
Default RE: Printing a text file from Delphi

Not sure if you want to print the file directly or not, but here is the simplest way to get it done!

With a memo on your form with buttons and stuff, do...

Memo1.Lines.LoadFromFile('C:whatever\your\filename _is.txt');

Then add this code in your project:

uses Printers; // Make sure this is in your project's
// uses clause

procedure PrintStrings(Strings: TStrings);
var
Prn: TextFile;
i: word;
begin
AssignPrn(Prn);
try
Rewrite(Prn);
try
for i := 0 to Strings.Count - 1 do
writeln(Prn, Strings.Strings[i]);
finally
CloseFile(Prn);
end;
except
on EInOutError do
MessageDlg('Error Printing text.', mtError, [mbOk], 0);
end;
end;

{ End code listing }

To print out the contents of a TMemo, use the following code:

PrintStrings(Memo1.Lines);

This is the easiest way I know of. Code taken off Borland's web site! ... and it works for me!

Hope this may help ya!

John Jarrett
Reply With Quote
  #10  
Old 11-15-2002, 02:20 AM
BlindReaper BlindReaper is offline
Member
 
Join Date: Nov 2002
Posts: 32
Default RE: Printing a text file from Delphi

I thank you, this helped me!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 05:45 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.