Data Access User Manual > Rogue Wave Views Data Access Gadgets > Utility Classes > The IliFormat Class
 
The IliFormat Class
The IliFormat class is used to format values into character strings using specific rules. A format can be user-defined or predefined. Once an IliFormat has been created, it can be named and referenced whenever required. This can be done using the aliasing mechanism provided in the IliFormat class.
You can specify formats for numbers, dates, or character strings.
// Create a predefined format named "MyFormat".
IliFormat::AddAlias(“MyFormat”,
“#,##0.00 FF.”,
IliNumberFormatType);
 
IliFormat fmt(“MyFormat”);
IliValue val = someField->f_getValue();
const char* txt = val.getFormatted(fmt);
IlvPrint("Here is the formatted value : %s", txt);
The IliFormat class controls the format specification and uses some global settings. These settings include properties such as the character that is used to represent a decimal point. Consequently, the IliFormat class contains a set of static member functions that can be used to query and set the global settings.
IliFormat::SetDecimalPoint(’,’);
IliFormat::SetThousandsSeparator(’ ’);
IliFormat::SetCurrencySymbol("F.");
...
For more information on the syntax used to specify a format, see Format Syntax.
It is also possible to code formats in C++ by subclassing the IliFormatIpl class as the following code extract shows:
#include <ctype.h>
#include <ilviews/dataccess/format.h>
 
const char* MyFormatAlias = "FancyFormat";
const char* MyFormatName = "FancyFormat";
 
// This format reverses the case of alphabetic
// characters: lowercase are displayed uppercase and
// vice-versa.
 
class FancyFormat
: public IliFormatIpl
{
public:
FancyFormat()
: IliFormatIpl(MyFormatName)
{}
 
virtual IliFormatType getType() const {
return IliStringFormatType;
}
 
virtual void formatString(IliString& dest,
const char* src) const {
if (src) {
if (isEditModeOn())
dest << src;
else
while (*src) {
if (isalpha(*src)) {
if (isupper(*src))
dest << (char)tolower(*src);
else
dest << (char)toupper(*src);
}
else
dest << *src;
++src;
}
}
}
};
 
int main() {
...
IliFormatIpl::AddCustomFormat(new FancyFormat());
IliFormat::AddAlias(MyFormatAlias,
MyFormatName,
IliStringFormatType);
...
}

Version 6.2.1
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.