Skip to main content

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

NameTypeDescription
aFileNamestring, constPath 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 GetACP when 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 short Read count and permits concurrent writers through fmShareDenyNone.
  • 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

External references

Created 2026-07-15