IPointer

Top  Previous  Next

Pretranslated C# code > Pointers > IPointer

`IPointer<T>` is the common compatibility interface implemented by typed pointer values.

 

 

public interface IPointer<T> : IDisposable

{

    int Length { get; }

    int Capacity { get; }

    int Position { get; }

 

    bool IsNull();

    void SetNull();

 

    T Deref();

    void Assign(T value, int index = 0);

 

    void Inc(int count);

    void Dec(int count);

}

 

 

The interface represents the operations most often produced from Delphi pointer expressions.

 

Dereferencing

 

`Deref()` corresponds to:

 

 

P^

 

 

Example:

 

 

int value = p.Deref();

 

 

`Assign(value)` corresponds to:

 

 

P^ := Value;

 

 

Example:

 

p.Assign(value);

 

 

The optional index is relative to the current pointer position and uses the unit of the concrete pointer type:

 

 

p.Assign(value, 3);

 

 

For `Pointer<T>`, this accesses element `3`. For `Pointer` and `UntypedPointer`, it accesses byte offset `3`.

 

Pointer movement

 

`Inc(count)` and `Dec(count)` correspond to:

 

 

Inc(P, Count);

Dec(P, Count);

 

 

The movement unit depends on the concrete type.

 

Helper properties

 

`Length`, `Capacity`, and `Position` are runtime helper properties. They are not Delphi language properties.

 

Their units follow the concrete pointer type:

 

bytes for `Pointer` and `UntypedPointer`
elements for `Pointer<T>`
UTF-16 code units for `PChar`

 

`Length` normally describes the accessible remainder of the current view. `Position` describes the current offset from the backing start. `Capacity` describes the available backing or view capacity as defined by the concrete pointer type.

 

Important interface limitation

 

The pointer implementations are structs. Converting a pointer to `IPointer<T>` boxes the value. Mutating operations such as `Inc`, `Dec`, or `SetNull` would then modify the boxed copy rather than the original pointer variable.

 

Therefore, Delphi2C# should not route generated pointer arithmetic through `IPointer<T>`. The interface is intended only as a compatibility surface for APIs that do not rely on mutating the caller's pointer value.

 



This page belongs to the Delphi2C# Documentation

Delphi2C# home  Content