Difference between revisions of "OpenFile"

From SCAR Divi Manual
Jump to: navigation, search
(Created page with "==Definition== <source lang="scar" lines="false"> function OpenFile(Path: string; Shared: Boolean): Integer; </source> ==Availability== SCAR Divi 3.00 > Current ==Description==...")
 
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
==Definition==
 
==Definition==
 
<source lang="scar" lines="false">
 
<source lang="scar" lines="false">
function OpenFile(Path: string; Shared: Boolean): Integer;
+
function OpenFile(const Path: AnsiString; const Shared: Boolean): Integer;
 
</source>
 
</source>
  
Line 8: Line 8:
  
 
==Description==
 
==Description==
Opens a file specified by '''Path''' for reading access if it is a valid path name. If the path name is valid it will return the handle of the file stream to the file in the files resource manager, if not, it raises an exception. If '''Shared''' is [[true]], the file can be accessed by other processes while it is in use by SCAR Divi, if it is [[false]] the script gets exclusive access until [[CloseFile]] is used to close the file stream.
+
Opens a file specified by '''Path''' for reading access. If the path name is valid it will return the handle of the file stream to the file in the files resource manager, if not, it raises an exception. If '''Shared''' is [[true]], the file can be accessed by other processes while it is in use by SCAR Divi, if it is [[false]] the script gets exclusive access until [[CloseFile]] is used to close the file stream. If you wish to write a file you can use the [[RewriteFile]] function.
  
 
==Example==
 
==Example==
Line 22: Line 22:
  
 
   f := OpenFile(LogsPath + 'Test.txt', False);
 
   f := OpenFile(LogsPath + 'Test.txt', False);
   ReadFileString(f, s, FileSize(f))
+
   ReadFileString(f, s, FileSize(f));
 
   WriteLn(s);
 
   WriteLn(s);
 
   CloseFile(f);
 
   CloseFile(f);
 +
 +
  DeleteFile(LogsPath + 'Test.txt');
 
end.
 
end.
 
</source>
 
</source>
 +
 +
Output:
 +
Hello World!
  
 
==See Also==
 
==See Also==
 
*[[RewriteFile]]
 
*[[RewriteFile]]
 +
*[[AppendFile]]
 
*[[CloseFile]]
 
*[[CloseFile]]
 
*[[FileSize]]
 
*[[FileSize]]

Latest revision as of 00:25, 3 November 2011

Definition

function OpenFile(const Path: AnsiString; const Shared: Boolean): Integer;

Availability

SCAR Divi 3.00 > Current

Description

Opens a file specified by Path for reading access. If the path name is valid it will return the handle of the file stream to the file in the files resource manager, if not, it raises an exception. If Shared is true, the file can be accessed by other processes while it is in use by SCAR Divi, if it is false the script gets exclusive access until CloseFile is used to close the file stream. If you wish to write a file you can use the RewriteFile function.

Example

var
  f: Integer;
  s: string;

begin
  f := Rewritefile(LogsPath + 'Test.txt', False);
  WriteFileString(f, 'Hello World!');
  CloseFile(f);

  f := OpenFile(LogsPath + 'Test.txt', False);
  ReadFileString(f, s, FileSize(f));
  WriteLn(s);
  CloseFile(f);

  DeleteFile(LogsPath + 'Test.txt');
end.

Output:

Hello World!

See Also