Retrieve a field pointer
- Last UpdatedApr 08, 2026
- 2 minute read
This scenario guides you through the steps required to retrieve the field pointer for a record. A pointer to the field allows direct access to the memory for that field.
To identify the code associated with each step, see the code comments in the Example code section.
To retrieve a field pointer
When performing this procedure, ensure that the locks applied match the desired task (that is, if the record is locked for reading, do not write to the memory at the field pointer).
Any changes to a field using the field pointer will not be tracked via Management of Change (MoC) since you are directly modifying shared memory.
- Open the Program.cs file from the created project.
- Open the RealTime database (RTDB).
- Lock the analog table for reading.
- Find the analog record to get its pointer by name.
- Lock the analog record for reading.
- Get the field pointer.
- Unlock the analog record.
- Unlock the analog table.
Example code
IRealTimeDatabase database = new RealTimeDatabase();
try
{
// Open the RTDB.
if (!database.IsOpen())
{
database.Open();
}
using (IRealTimeTable table = new RealTimeTable("analog"))
{
ITableLockRequestType tableLockRequest = new TableLockRequestType();
IRecordLockRequestType recordLockRequest = new RecordLockRequestType();
// Lock the analog table for reading.
table.Lock(tableLockRequest.SAFE_READ);
// Find the analog record to get its pointer by name.
var nameField = new RealTimeStringField(table, "name");
using (var record = table.FindRecord(nameField, "AutoCommandAnalog01"))
{
// Lock the analog record for reading.
record.Lock(recordLockRequest.SAFE_READ);
// Get the field pointer.
var flagField = new RealTimeField(table.Name, "flag");
var flagFieldPointer = record.GetPointerToField(flagField);
// User code that uses the field pointer.
} // Leaving scope releases the analog record lock.
} // Leaving scope releases the analog table lock.
}
catch (Exception ex)
{
Console.WriteLine(quot;Error getting the field pointer: {ex.Message}");
}