Declaration Rules — Where to Declare Each Type

Where each Dew.Math type may be declared:

Declaration contextValue types (Vector, Matrix, VectorInt, MatrixInt)Class types (TVec, TMtx, TVecInt, TMtxInt)
Local variableYES (primary use)YES — with CreateIt/FreeIt
Class/record fieldNO — neverYES — with constructor/destructor

Rule 1: Value types must only be local variables. Never use them as fields.

Rule 2: Class types as fields — use constructor + destructor (not CreateIt/FreeIt):

class Something {
public:
    Something() { FData = new TVec(); }
    ~Something() { delete FData; }
    Something(const Something&) = delete;             // one owner per TVec
    Something& operator=(const Something&) = delete;
private:
    TVec* FData;
};

Rule 3: CreateIt / FreeIt are for local objects only — never for fields.

StringList — value type for string lists (unit: StringVar)

The C++ edition has no StringList record. Its string list, tStringList (header MtxStrings.h), is an ordinary class with a public constructor and destructor: declared as a local variable it needs no new and no delete, and it is freed when it goes out of scope. Pass &sl wherever a tStrings* or tStringList* parameter is expected. It has the same API as TStringList (Add, Delete, LoadFromFile, SaveToFile, Count, Strings[], Text, Sort, Find, IndexOf, etc.) but requires no Create or Free — the compiler manages its lifetime automatically via an internal interface reference.

Use StringList instead of TStringList to avoid Create/Free boilerplate. It can be used as a local variable or as a field in classes or records. Unlike Vector/Matrix, StringList has no memory pool caching — each instance manages its own internal TStringList via interface reference counting.

// C++: tStringList is an ordinary class - no new, no delete
tStringList sl;
sl.Add("line 1");
sl.Add("line 2");
sl.SaveToFile("output.txt");
// freed automatically when sl goes out of scope

StringList auto-converts to TStrings and TStringList via implicit operators, so it can be passed directly to any method expecting those types.

See also: topic type-selection for choosing between value types and class types.