Solved

I/O error 104 when printing a file

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

831 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