Solved

Help needed, easy question for experts!

Posted on 2003-11-23
6
295 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
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

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…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

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