LoadFileToStringANSI
Function LoadFileToStringANSI( const aFileName : string) : string
Example
procedure ScriptEvent(var Value: variant);
begin
Value := LoadFileToStringANSI('C:\Fictional\Inbound\legacy-message.txt');
end;
Usage
LoadFileToStringANSI reads an entire file as text using Velox's system ANSI encoding.
Parameters
| Name | Type | Description |
|---|---|---|
aFileName | string, const | Path of a file known to use the Velox host's system ANSI code page. |
Returns
The ANSI-decoded Velox string, or an empty string for a stable empty file.
Errors
Path, open, seek, allocation, read and conversion failures propagate. No partial text is returned.
Usage notes
Use this entry only for a governed legacy contract whose code page matches the Velox host. Prefer UTF-8 for new interchange formats.
Additional Technical Info
LoadFileToStringANSI reads a complete file and decodes every byte with Delphi TEncoding.ANSI. On Windows this is the host system ANSI code page captured by a process-wide encoding singleton; it is not UTF-8 and the file does not identify its own code page.
The example reads a fictional legacy text file. It is source-reviewed and was not executed by the documentation workflow.
Implementation
The registered wrapper calls the overloaded vxFiles.LoadFileToString with TEncoding.ANSI. That function opens a read-only, share-deny-none TFileStream and calls vxStream.FileStreamToString. The helper reads the complete captured file size and calls GetString on the entire byte array. Because an encoding was explicitly supplied, GetBufferEncoding is bypassed.
Edge cases and quirks
- UTF-8 or UTF-16 BOM bytes are treated as ordinary ANSI bytes; no preamble is detected or removed.
- Bytes above ASCII can produce different text on Velox hosts with different system ANSI code pages. The process-wide singleton captures Windows
GetACPwhen first created and remains stable thereafter. - Current Delphi MBCS conversion is permissive. Invalid or unmappable byte sequences follow the selected Windows code page's conversion/failure behaviour and must not be treated as input validation.
- File size is narrowed to signed
LongInt; the helper ignores a shortReadcount and permits concurrent writers throughfmShareDenyNone. - Embedded zero bytes become U+0000 characters inside the managed string rather than ending the read.
Side effects
Opens and reads the file without deliberately modifying it.
Performance and concurrency
The full byte buffer and Unicode result coexist in memory. The call is synchronous and is not an atomic snapshot when another process writes the shared file.
Related entries
LoadFileToStringdetects supported BOMs and otherwise falls back to ASCII.LoadFileToStringUTF8provides a portable Unicode byte contract.SaveStringToFileANSIperforms the corresponding ANSI encoding.
External references
- Embarcadero
TFileStream.Create,TEncoding.ANSIandTEncoding.GetString- the exact Delphi file and decoder path used by Velox. - Free Pascal
TFileStream.CreateandTEncoding.ANSI- compatible code-page context; current Windows conversion behaviour is Delphi-specific.