Solved

Help needed, easy question for experts!

Posted on 2003-11-23
6
298 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
[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
6 Comments
 
LVL 9

Accepted Solution

by:
ginsonic earned 25 total points
ID: 9805867
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
ID: 9805871
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
ID: 9805931
HI,
You also can use "try..except..end" to catch the error.
Sincerely,
Nestorua.
0
 
LVL 5

Expert Comment

by:DeerBear
ID: 9810056
Hi,

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

HTH,

Andrew
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

717 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