View Full Version : Delphi (2) file test.

12-06-2002, 04:02 PM
I am trying to manipulate text files in Delphi. My program works but if the file dosn't exist generates an error.
I want to use If..then..else to test for the files existance using a string (of type string) containing the files name. I am unable to fing the correct syntax for this test (assuming it is the best method).


12-06-2002, 04:44 PM
A few seconds in google gave me a bit of code allegedly 'the same as' that in a Delphi unit:
'If FileExists(FFilename) then ... '

I've forgotten how I used to do it in Turbo Pascal 3 and 4-- I think it involved turning off the error failure and using IOERROR values.

14-06-2002, 12:52 PM
I suggest using the safer method of the try..catch statement.

It's a safe way of testing stuff that won't hang your system - just remember though, that delphi itself will intercept errors before the try..catch statement so execute the program outside the delphi environment if you want to test your code properly.

Have a look at <http://delphi.about.com> or the delphi help files - if you haven't got one of the pc world mags with a new delphi edition, i suggest you buy one.

The delphi help files are very good - if you already know what sort of thing you are after, they're not so good if you are trying to learn delphi (in my experience).

Hope this is of some help,
MarkOS X

17-06-2002, 07:44 PM
Try this

if fileexists('filename.txt') then

else showmessage('message text');

17-06-2002, 09:57 PM
Thanks for the suggestions - I am using the If then cos I got it to work :) and there are only two results.
I am using Delphi 2 as I own a copy and this is a paid job (sort of :)

I agree totally about the help files.