Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileExists not finding files that exist 1

Status
Not open for further replies.

nigeldutton

Programmer
Feb 25, 2003
2
AU
This is the code I am running

if FileExists(ImageToLoad) then begin
JPG := TJpegImage.Create;
try
JPG.LoadFromFile(ImageToLoad);
Draw(X,Y,JPG);
finally
JPG.Free;
end; //try
end; //if FileExists

The ImageToLoad string is a network path to a busy server where the photos are stored.

Often images that I know exist are not printed or are missing from the view screen. FileExists is returning false.

I think that this is because occasionally the server is very busy and the FileExist function is timing out and returning false.

What I need to know - is there a way to increase the default time out for FileExists?
 
Why not omit the FileExists call entirely and instead trap the error at the point of LoadFromFile?
 
I did not test this, but you should be able to get the general idea, anyway...
[tt]
function WaitForFileExists( filename:string;
timeout:LongInt ): boolean;
begin
timeout:=GetTickCount + timeout;
repeat
Result:=FileExists(filename);
if (not Result) then begin
Sleep(250); { wait 1/4 second, and try again ? }
Application.MainForm.Update;
Application.ProcessMessages;
end;
until Result or ( GetTickCount > timeout )
end;
[/tt]
Timeout is is milliseconds, so to wait up to three seconds
for the file, you would do:
[tt]
if WaitForFileExists(ImageToLoad, 3000) then begin {...}
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top