Range Checking

MtxVec has its own range checking system, independent of the Delphi/C# compiler.

How it works:

  • MtxVec methods validate all index/length parameters before processing
  • Violations raise EMtxVecRangeError with a descriptive message
  • This checking is controlled by Assertions, not by the compiler range-check flag

Enabling/disabling:

SettingEffectUse case
Assertions ONFull range checking, object cache disabledDebug builds
Assertions OFFNo range checking, object cache activeRelease builds (fastest)

In Delphi: Project → Options → Compiler → Assertions. In C#: MtxVec range checking is always active (not controlled by compiler flag).

Important: MtxVec's index validation is Assertions-based and entirely separate from the Delphi compiler's {$R+} switch — see "Delphi {$R+}" below for how the compiler's own checks can still fire on MtxVec data. Access sub-ranged data through the Values property, which honours the sub-range window:

// C# does not have a compiler-level range check toggle like Delphi {$R+}.
// MtxVec range checking is always active in C#.
// SetSubRange works the same — no false alarm issues in C#.
TVec a = null, b = null;
TMtxVec.CreateIt(out a, out b);
try {
    a.LoadFromFile("data.vec");
    b.SetSubRange(a, 2, 10);     // b is a view of a[2..11]
    b.Values[0] = 1.0;           // writes to a[2]
    b.SetSubRange();             // release view
} finally {
    TMtxVec.FreeIt(ref a, ref b);
}

Recommendation: Use Assertions ON during development, OFF for release.

Because those checks are generated in your own unit, this happens even when MtxVec itself was compiled without {$R+} — the library's build setting cannot remove a check the compiler placed in your code. Working with matrices is the most common way to hit it.

The library source can itself be built with {$R+}, and false positives are not excluded there either — the library's own tests account for that discrepancy. When you use the library in source form, do not build with {$R+}, and switch it off locally with {$R-} around code that indexes vector or matrix elements.

None of this affects MtxVec's own range checking: it is Assertions-based and validates every index and length argument regardless of the {$R+} setting.

In C#, MtxVec range checking is always active and there is no {$R+} equivalent. No special handling is needed for SetSubRange in C#.