Solved

I/O error 104 when printing a file

Posted on 1998-08-02
4
1,768 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

623 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