Click or drag to resize

MemoRead Function

X#
Return the contents of a text file as a string.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.19
Syntax
 FUNCTION MemoRead(
	cFileName AS STRING
) AS STRING
Request Example View Source

Parameters

cFileName
Type: String
The name of the text file to read from disk, including an optional drive, directory, and extension. SetDefault() and SetPath() settings are ignored; the Windows default is used unless you specify a drive and directory as part of the file name. No extension is assumed.

Return Value

Type: String
The contents of the file.
The maximum file size that can be read is MAX_ALLOC bytes — the maximum size of a string. If cFileName does not exist, MemoRead() returns a NULL_STRING.
If it exists, this function attempts to open the file in shared mode and, if successful, it proceeds.
If access is denied because, for example, another process has exclusive use of the file, MemoRead() returns a NULL_STRING and NetErr() is set to TRUE.
Remarks
MemoRead() reads a disk file into memory, where it can be manipulated as a string or assigned to a memo field. MemoRead() is used with MemoEdit() and MemoWrit() to edit an imported disk file; then write it back to disk. This function does an automatic OEM to ANSI conversion when SetAnsi() is FALSE.
Remarks
This function should NOT be used to read the contents of a binary file (such as a word document). Use MemoReadBinary() in stead .
Examples
This example uses MemoRead() to assign the contents of a text file to the Notes memo field and to a character variable:
X#
1REPLACE Notes WITH MemoRead("temp.txt")
2cString = MemoRead("temp.txt")
This example defines a function that edits a disk file:
X#
1FUNCTION Editor(cFile)
2    LOCAL cString AS STRING
3    If(cString := MemoRead(cFile)) = NULL_STRING
4        ? "Error reading " + cFile
5        RETURN FALSE
6    ELSE
7        MemoWrit(cFile, MemoEdit(cString))
8        RETURN TRUE
9    ENDIF
See Also