Converting back and forth between a Field and a Widget Annnotation.

Q: Searching this forum I found the following line:
Annot annot(field.GetSDFObj());

Since I need to jump back and forth between "Field" and "Annot", the
above statement is crucial.

The question is: what if I want to move in the opposite direction?
Let's say I am navigating
through Annots, and need to convert (cast?) one of them to a Field
(which are higher level and thus easier to deal with).

Is there such mechanism?

This is a correction to my previous message. I have been programming
and reading the documentation,
and I now realize that the member 'GetSDFObj()' can be applied to
both Field and Annot (and to
many other classes as well):

Annot annot = field.GetSDFObj());
Obj dict = annot.GetSDFObj();

I do have other, more advanced questions.

My current problem is that I can't figure out how to retrieve a
variable of type 'string' (such as
'T' or 'TU') from a dict.

Besides casting of the low-level object, you can also convert an
annotation into a Widget and then call Widget.GetField() method. For
example:

// In C++

if (annot.GetType() == Annot::e_Widget) {
   Annots::Widget w(annot);
   Field f = w.GetField();
   if (f.IsValid()) {
      // Note: A widget may not be associated with a field.
   }
}

My current problem is that I can't figure out how to retrieve a variable of type 'string' (such as
'T' or 'TU') from a dict.

You can use SDF (a.k.a. Cos) API. For example:

Annot annot = field.GetSDFObj());
Obj dict = annot.GetSDFObj();

Obj t = dict.FindObj("T");
if (t != null) {
   string val = t.GetAsPDFText(); // We expect a string object
}

In C++:

Obj t = dict.FindObj("T");
if (t)
{
   UString n;
   t->GetAsPDFText(val);
   cout << n;
}

For example of how to use SDF API, please see SDFTest sample:
  http://www.pdftron.com/pdfnet/samplecode.html#SDF