/*$DA   is the data widget.
     -TRM flag is for variable width
            fields with a terminator
            character.
     +RD    refreshes the data.
     +UD    updates the value when you edit it.

     -P     Means it is a string variable, basically.

     ,32    sets the tag string width.
            See Data Tag Width.

     ,RT=I16 means the value is 2 bytes.
            See DocDataFormat() and DocDataScan().
*/

I16 i = 0;
U8  buf[8];

U0 UpdateGlobalTask(I64)
{
    while (TRUE)
    {
        i++;
        Sleep(1);
    }
}

U0 DataDemo()
{
    CDocEntry *doc_e;

    //This is the command line document.
    CDoc *doc = DocPut;

    //We do this to prevent access to
    //doc_e->data before it is set.
    Bool unlock = DocLock(doc);

    //You might set the DOCF_FORM flag.
    //  doc->flags|=DOCF_FORM
    //if you wish.

    Spawn(&UpdateGlobalTask, NULL, "Update Global",, Fs);

    "Enter editor overstrike mode\n"
    "and you can modify the value.\n"
    "However, changes happen immediately,\n"
    "so it's tricky.\n\n";

    //Use <CTRL-l> for the $DA...$ format.
    doc_e = DocPrint(doc, "$DA-TRM+RD+UD,RT=I16,A=\"%%7d\"$\n");
    doc_e->data=&i;

    StrCopy(buf, "Terry");
    doc_e = DocPrint(doc, "$DA-P+RD+UD,LEN=7,A=\"Str:%%s\"$\n");
    doc_e->data = buf;

    if (unlock)
        DocUnlock(doc);
}

DataDemo;

//See PopUpExtents().