SystemReset (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example should be executed from a command line formatted like this: "SystemReset_proj foo.txt". The file path is relative to the project directory.

Code

function FileIsThere(FileName: string): Boolean;
{ Boolean function that returns True if the file exists; otherwise,
  it returns False. Closes the file if it exists. }
 var
  F: file;
begin
  {$I-}
  AssignFile(F, FileName);
  FileMode := 0;  {Set file access to read-only. }
  Reset(F);
  CloseFile(F);
  {$I+}
  FileIsThere := (IOResult = 0) and (FileName <> '');
end;  { FileIsThere }

procedure TForm1.Button1Click(Sender: TObject);
begin
  if FileIsThere(ParamStr(1)) then { Get file name from command line. }
    Canvas.TextOut(10, 10, 'File exists')
  else
    Canvas.TextOut(10, 10, 'File not found');
end;

Uses

Personal tools
Assistance