Forum Home
Press F1
 
Thread ID: 20793 2002-06-12 04:02:00 Delphi (2) file test. Guest (0) Press F1
Post ID Timestamp Content User
53945 2002-06-12 04:02:00 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).

Regards.
Guest (0)
53946 2002-06-12 04:44:00 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.
Guest (0)
53947 2002-06-14 00:52:00 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
==========================
Guest (0)
53948 2002-06-17 07:44:00 Try this


if fileexists('filename.txt') then
begin



else showmessage('message text');
Guest (0)
53949 2002-06-17 09:57:00 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.
Guest (0)
1