Skip to main content

SaveStringToFile

Procedure SaveStringToFile( const aContents, aFileName : string)

Example

procedure ScriptEvent(var Value: variant);
begin
// Current supported Windows-default equivalent.
SaveStringToFileANSI('Fictional payload',
'C:\Fictional\Outbound\message.txt');
end;

Usage

SaveStringToFile is unsafe in the current Velox version and must not be called. It can fail or leave the script in an invalid state instead of writing the file reliably.

Parameters

NameTypeDescription
aContentsstring, constIntended text content.
aFileNamestring, constIntended destination path.

Returns

This procedure has no return value.

Errors

A call can fail outside normal Velox scripting error handling. Do not use try..except as a safety mechanism around this entry.

Usage notes

Use SaveStringToFileANSI, SaveStringToFileASCII, SaveStringToFileUTF8, SaveStringToFileUTF16 or SaveStringToFileUTF16BE according to the required file encoding.

Additional Technical Info

SaveStringToFile is declared to scripts as a procedure, but its current runtime registration points to an adapter declared as a Delphi function returning string. That signature mismatch is ABI-incompatible. Do not call SaveStringToFile from Velox scripting until the product adapter is corrected; use an explicit encoding-specific writer instead.

The example deliberately uses SaveStringToFileANSI, the current Windows-default equivalent, rather than invoking the unsafe entry. It targets fictional data/path, is source-reviewed and was not executed by the documentation workflow.

Implementation

At compile time, SIRegister_vxFiles publishes Procedure SaveStringToFile(...). At runtime, RIRegister_vxFiles_Routines resolves that name to @SaveStringToFile_P, whose actual declaration is Function SaveStringToFile_P(...): string. Its body calls the intended native overload but never assigns its own result.

PascalScript constructs the external invocation from the compiled procedure declaration and therefore supplies no result slot. The Delphi target expects storage for a managed-string result. This calling-contract mismatch can corrupt process state or fault at call time; safe execution of the intended body cannot be assumed.

If correctly registered as a procedure, the intended native overload would select TEncoding.Default, which is ANSI on the supported Windows runtime, then use the same destructive file writer as SaveStringToFileANSI.

Edge cases and quirks

  • The import name resolves, so this is not a compile-time or Cannot Import failure. The hazard occurs when the external call is made.
  • There is no safe argument combination, including empty text, that removes the ABI mismatch.
  • The native implementation's intended default is host ANSI, not UTF-8, and it emits no BOM.
  • The intended writer also truncates before encoding and ignores the terminal Write count; fixing only the adapter would not fix those separate reliability limitations.
  • If its intended Windows writer is reached, normal CREATE_ALWAYS handling follows a symbolic link and truncates the link target.

Side effects

Undefined at the script boundary because the call ABI is invalid. If control reaches the intended native body, it can create or replace the destination file.

Performance and concurrency

Not applicable while the entry is unsafe. The intended native writer performs a synchronous full-string encoding and direct non-atomic file replacement.

Related entries

External references

Created 2026-07-15