I have been experimenting with my PlayList Writer programme and observed a bug. I was previously using findfirst onClick to check if the playlist file was present:
var
searchResult : TSearchRec; // Test File
if findfirst('PlayListStephen.m3u', faAnyFile, searchResult) = 0 then //
// after the if
FindClose(searchResult); //
On the occasions when the specified file was not present, its absence was detected, and the else part of the code, not shown here, worked. Well that sounds all right. But, I only recently realised that as a result of not finding the file, it created one. Which is not the intention.
I have experimented with the next approach, if FileIsInDirectory. But I think I must have the coding wrong because
- when the file is present it is detected – no problems, but when I delete the file and run the programme again
the file is detected, even though it is not there. - Then a new file is made. Which is not the intention
In order to use ‘FileIsInDirectory’ I added LazUtils to the Project Inspector and added FileUtil to Uses:
Here is the code for the onClick event to test the file is present, and of course the target file sits in the same folder as all the other project files:
procedure TForm1.BitBtn2Click(Sender: TObject); // Test File
begin
if FileIsInDirectory('PlayListStephen.m3u', 'C:\Users\stephanos\MyFiles\Delphi(Lazarus)\
PlayListV24-TimeLimit-FileIsInDirectory\') then
begin //
BitBtn3.Enabled := True;
Form1.ActiveControl := BitBtn3;
Open.Enabled := True;
Label3.Enabled := True;
Label3.Font.Color := clMaroon;
Label3.Caption := 'File present. Click the Open File button to continue '#13#10' or press ALT + F to continue';
end
else
Begin
Label3.Caption := 'File NOT present'; //begin
end; // End of if FileIsInDirectory('Play …….
Test.Enabled := False; BitBtn2.Enabled := False;
end;
So I really do not know what I am doing. Is there a way to check a file is present and simply do noting else except return a value that can be checked, with no other activity?
Thanks and wait to hear