Solved

I/O error 104 when printing a file

Posted on 1998-08-02
4
1,714 Views
Last Modified: 2008-02-01
Hi experts,

with the following source code, I try to print an ASCII text file on my printer:

procedure TfrmPrintFile.Button3Click(Sender: TObject);

var filename: string;
    printer:textfile;
   
begin
  if opendialog1.execute then
   filename:=opendialog1.filename;
  assignPrn (printer);
  {$I-} rewrite (printer); {$I+}
  if ioresult<>0 then halt;
  while not eof (printer)
   do writeln (printer,filename);
  closefile(printer);
end;



Unfortunately Delphi complains about an  I/O error Nr. 104

in the line:

while not eof (printer)

What am I doing wrong here?

With kind regards

Christian

0
Comment
Question by:mathes
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
Matvey earned 50 total points
ID: 1359502
Here, try this:
c u, Matvey

    var
      Text: TextFile;
    begin
      AssignPrn(Text);
      try
        ReWrite(Text);
        Printer.Canvas.Font.Name:='Courier';
        Printer.Canvas.Font.Size:=14;
        Printer.Canvas.Font.Style:=[];
        { do your writing here }
        WriteLn(Text,'My Text Here');
        {when you've finished writing}
      finally
        CloseFile(Text);
      end;
    end;
0
 

Author Comment

by:mathes
ID: 1359503
Dear Matvey,

I basically know how one can print a file. But I don't know my error in the posted source. So can you please review my code and stick please a little bit closer at it with your reply? (You did not explain to me the error 104). In this situation I don't need to set a specific font. A simple printout will perfectly meet my expectations. Moreover I don't know at program start what I want to print. This decision is made by the user during run time of the program. This is the reason why I have to open a file and send its content to the printer. In my specific situation I can't send a certain string to the printer- as you do it in your sample code- because the concrete content of the strings are not known at program start.

So please, try it again.

With kind regards

Christian



0
 
LVL 3

Expert Comment

by:Matvey
ID: 1359504
Hi. Your code produces the error on the "EOF(printer)" statement. It happends because the printer isn't concidered a readable device, so you can read it to find it's end. Therefore you have to avoid this statement.
To print your file you write something like this:

var filename, s: string;
    printer, t: textfile;
begin
  if opendialog1.execute then
    filename:=opendialog1.filename;
  try
    assignPrn(printer);
    rewrite(printer);
    reset(t, FileName);
    while not eof(t) do begin
      readln(t, s);
      writeln(printer, s);
    end;
  finally
    closefile(t);
    closefile(printer);
  end;
end;

-Sorry I was unclear and not specific.
All the best,
--Matvey
0
 

Author Comment

by:mathes
ID: 1359505
Dear Matvey,

thank you for reviewing my code concerning file printing. Now all works perfectly
as I like it.
Please excuse my unclear question. Of course it was well intended from
you when you provided me with details about font settings. I did not tell
you that I prefer a spartanic printout in this specific case.

With kind regards.

Christian

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now