Solved

Help needed, easy question for experts!

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
calling procedure inside activexForm from secondform 1 232
delphi exception 7 63
Reconfigure Delphi Install? 2 47
FMX and jaudiotracker playing memory stream 29 67
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

20 Experts available now in Live!

Get 1:1 Help Now