I have this piece of code that drives me crazy.
FUNCTION DiskInDrive(CONST DriveNumber: Byte): BOOLEAN;
VAR ErrorMode : Word;
BEGIN
RESULT:= FALSE;
ErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);
TRY
if DiskSize(DriveNumber) <> -1 { %%%% THIS IS VERY SLOW IF THE DISK IS NOT IN DRIVE !!!!!! }
THEN RESULT:= TRUE;
FINALLY
SetErrorMode(ErrorMode);
END;
END;
It checks if the drive is ready for use (and also if the specified drive letter matches the valid drive). The problem is that when I try to access a disconnected network drive (the network folder displayed as a drive), it freezes for about 10-30 seconds.
The code is in the constructor of component I.
How can I check the disk without waiting for this for a long time?
source
share