Solved

I/O error 104 when printing a file

Posted on 1998-08-02
4
1,747 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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