Solved

Help needed, easy question for experts!

Posted on 2003-11-23
6
293 Views
Last Modified: 2011-08-18
I have this program so far - i need to return an error message if the file entered doesnt exist....

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var Input      : text;
      I          : integer;
      Lineoftext : string;
      S : string;

  Begin

  Readln (S);

  Reset(input,S);
  for I:=1 to 10 do begin
  Readln (Input,Lineoftext); {Reading a Lineoftext from input file}
  writeln (Lineoftext);
  end;
  Closefile (Input);
  readln;
  end.


Thanks :)

0
Comment
Question by:jarhys
6 Comments
 
LVL 9

Accepted Solution

by:
ginsonic earned 25 total points
Comment Utility
Just use FileExists function as:

if not FileExists( S )  then begin
  ShowMessage( 'The file don't exist!' );
  Exit;
end;
0
 
LVL 8

Assisted Solution

by:gmayo
gmayo earned 25 total points
Comment Utility
if FileExists(LineOfText) then begin
   ...file exists...
   ExitCode := 0;
end else begin
   ... file does not exist...
   ExitCode := 1; // or whatever
end;

It's in the SysUtils unit which you already include.

Geoff M.
0
 
LVL 4

Expert Comment

by:nestorua
Comment Utility
HI,
You also can use "try..except..end" to catch the error.
Sincerely,
Nestorua.
0
 
LVL 5

Expert Comment

by:DeerBear
Comment Utility
Hi,

Eventually you can also use FileStream, which would also allow for more
flexybility in your data processing.

HTH,

Andrew
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

15 Experts available now in Live!

Get 1:1 Help Now