I check when the program is loaded for the existence of a file. But I can not understand how to make sure that if there is no file, the program is closed. And if there is continued work. I did this but the program and so and so close tell me what's wrong.

procedure TForm1.FormCreate(Sender: TObject); var fileName: string; begin fileName := 'D:\rec\Project2.dll'; if FileExists(fileName) then ShowMessage(fileName+' prodolgit!') else begin ShowMessage(fileName+' file ne najden prog zakroetsja!'); Form1.Close; end; end; 

2 answers 2

Very hard you can do this:

 else begin ShowMessage(fileName+' file ne najden prog zakroetsja!'); Halt; end; 
  • 2
    It is better to make checks before creating the forms. And if they do not pass, then go out and not create forms at all. - Albert Fomin

Make this check in the DPR file.
At the very beginning of the program after the first begin in DPR.
Before creating forms and initializing the application

 if not FileExists(FileName) then exit; Application.Initialize; 
  • Perhaps it is worth clarifying, for beginners, where to add this check. Those. bring a more complete fragment of the DPR file with such a check. - Kromster
  • At the very beginning of the program after the first begin in dpr. Before creating forms and initializing the application. - Albert Fomin
  • And in dpr, you can write exit; ? Did not know. - Igor
  • Of course you can :) And then after the last line of code in dpr, the finalization of units begins. - Albert Fomin