This tutorial shows you how to access a field without loading a whole record.
This tutorial shows
you how to get the value of a field in the GlobalSettings table. Records from the GlobalSettings
table are not loaded.
This
tutorial uses the BearerAvailablityCheckTSY
field. This field
contains the name of the TSY used to check for bearer availability.
Before you start, you must understand:
Make sure that you have created a session.
Create the field object in the tool or application process.
You construct a [[[ERROR: [NOKX000E] Unable to find definition for key reference 'CommsDat']]]CMDBField
<T>
object
and pass [[[ERROR: [NOKX000E] Unable to find definition for key reference 'CommsDat']]]KCDTIdBearerAvailabilityCheckTSY
to
the constructor. The symbol KCDTIdBearerAvailabilityCheckTSY
defines
the unique numeric Id for the BearerAvailablityCheckTSY
field.
... // Create the field object. The template parameter is TDesc, because the field value // is a short text description. // Use the "... new(Eleave).. " construction to create the field object. // Pass KCDTIdBearerAvailabilityCheckTSY as a parameter to the constructor. CMDBField<TDesC>* descField = new(ELeave) CMDBField<TDesC>(KCDTIdBearerAvailabilityCheckTSY); ...
Set the data that identifies the field and load the field
A descriptor field needs an additional call to set the size of the descriptor. CallSetMaxLengthL()
to set the size of the descriptor. This
function is a member of the field class [[[ERROR: [NOKX000E] Unable to find definition for key reference 'CommsDat']]]CMDBField
<TDesC>
.
Internally, the function causes the allocation of a descriptor. You must set
the size of the descriptor before you assign the data. You can also use the SetL()
function.
This function sets the length and assigns the data. The function is a member
of the field class [[[ERROR: [NOKX000E] Unable to find definition for key reference 'CommsDat']]]CMDBField
<TDesC>
.
... // The symbol "KMaxTextLength" defines the maximum length of short text. // The record Id is ALWAYS 1 for global settings table. descField->SetMaxLengthL(KMaxTextLength); descField->SetRecordId(1); //recorded is ALWAYS 1 for global settings table // Load the field. descField->LoadL(*iDb); ...
Check that the field has a value before you use it
... // Use the IsNull() function to check that the field has a value. // In this example, the code leaves if the field does not have a value. // Your code needs to handle a Null value appropriately. if(descField->IsNull()) { User::Leave(KErrNotFound); } else { // Either process the content of *descField in place, // or copy the content to another descriptor. // The processing depends on the structure of your code. // In this example, the content is copied into an RBuf for // further processing. RBuf buf; buf.CleanupClosePushL(); buf.CreateL(descField); ... // Do something with the data. ... // Delete the RBuf buffer CleanupStack::PopAndDestroy() ... } // Do not forget to delete the field object. delete descField; ...