company logo

Template result

The template result corresponds to the output created by WriteResult . The WriteResult function appends the text to the result string, i.e. it will collect the output from several templates.

Global template string

Template strings are thread variables, i.e. they are created separately for each thread. There is, however, only one template string for each thread, which can also be accessed as global variable __template__result_

It is, however, not suggested to refer to the template result via the global variable name, since the global variable name might be changed. A better way is referring to the template result via the functions describes below.

VARIABLES

  global    string   __template__result__;

SystemClass support

The SystemClass provides some functions in order to support handling the template result.

WriteResult

The WriteResult() function will append the data passed to the template string. Non-string values are converted to string according to the common conversion rules.

Write result supports converting data passed in the first parameter to HTML compatible data by converting HTML ^specific characters (e.g. < to &lt; or & to &amp; etc.)

During document generation data is passed to the document converter, which also converts Qt-HTML to Open Document standard. Qt-HTML is created when entering data in rich text edit control in the GUI frame work, i.e. most large text fields may contain Qt-HTML formatted text.

WriteResult() will be called automatically when running OSI templates. One may also call the function from within other OSI expressions.

// OSI

  WriteResult(data);      // appends content of data to template

  WriteResult(data,false);//  same as above

  WriteResult(data,true); // HTML convetion befor append data

Notes:

When the function name is also a class member function it has to be prefixed with the SystemClass scope.

Reset template result

The ResetResult() function will clear the template string. The application is responsible to reset the template string at the beginning or when terminating the processing.

// OSI

  RestResult();

  MyTemplate/(; // run OSI template

  File.Out(TemplateString()); // write to file

Get template string

TemplateString() is a function that returns the template result as string value. Calling TemplateString, one may display the template result or write it to file.

One may also call TemplateString() in order to add data directly to the template string or to reset the template string: The application is responsible to clear data in the template string when no longer being used, e.g. by calling ResetResult() .

// write template result to console

  Message(TemplateString);

// write template result to file

VARIABLES

  FileHandle    file;

PROCESS

  file.open(path,AccessModes::Write);

  file.append(TemplateString());

  file.close();

  ...

// append data to template string

VARIABLES

  string       &tsring &= TemplateString() // template string reference

PROCESS

  Message(tstring);

  tstring = '';

  Message(tstring);

  tstring += 'new value';

  Message(tstring);