52
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
142 | Page
"%" [index ":"] ["-"] [width] ["." prec] type
A format specifier begins with a % character. After the % come the following, in this order:
An optional argument zero-offset index specifier (that is, the first item has index 0), [index ":"]
An optional left justification indicator, ["-"]
An optional width specifier, [width]
An optional precision specifier, ["." prec]
The conversion type character, type
The following table summarizes the possible values for type:
d
Decimal. The argument must be an integer value. The value is converted to a string of
decimal digits. If the format string contains a precision specifier, it indicates that the
resulting string must contain at least the specified number of digits; if the value has
less digits, the resulting string is left-padded with zeros.
u
Unsigned decimal. Similar to 'd' but no sign is output.
e
Scientific. The argument must be a floating-point value. The value is converted to a
string of the form "-d.ddd...E+ddd". The resulting string starts with a minus sign if the
number is negative. One digit always precedes the decimal point.The total number of
digits in the resulting string (including the one before the decimal point) is given by the
precision specifier in the format string—a default precision of 15 is assumed if no
precision specifier is present. The "E" exponent character in the resulting string is
always followed by a plus or minus sign and at least three digits.
f
Fixed. The argument must be a floating-point value. The value is converted to a string
of the form "-ddd.ddd...". The resulting string starts with a minus sign if the number is
negative.The number of digits after the decimal point is given by the precision specifier
in the format string—a default of 2 decimal digits is assumed if no precision specifier is
present.
g
General. The argument must be a floating-point value. The value is converted to the
shortest possible decimal string using fixed or scientific format. The number of
significant digits in the resulting string is given by the precision specifier in the format
string—a default precision of 15 is assumed if no precision specifier is present.Trailing
zeros are removed from the resulting string, and a decimal point appears only if
necessary. The resulting string uses fixed point format if the number of digits to the
left of the decimal point in the value is less than or equal to the specified precision,
and if the value is greater than or equal to 0.00001. Otherwise the resulting string uses
scientific format.
n
Number. The argument must be a floating-point value. The value is converted to a
string of the form "-d,ddd,ddd.ddd...". The "n" format corresponds to the "f" format,
except that the resulting string contains thousand separators.
m
Money. The argument must be a floating-point value. The value is converted to a string
that represents a currency amount. The conversion is controlled by the CurrencyString,
CurrencyFormat, NegCurrFormat, ThousandSeparator, DecimalSeparator, and
CurrencyDecimals global variables or their equivalent in a TFormatSettings data
RasterEdge.com General FAQs for Products copy and email the secure download link to the assistance, please contact us via email (support@rasteredge & profession imaging controls, PDF document, image to
pdf links; add hyperlink to pdf online RasterEdge Product Licensing Discount s). After confirming the informations provided, we will send you an email that contains price(s) at a discount and the online order link for new licensing.
add url pdf; add a link to a pdf
34
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
143 | Page
structure. If the format string contains a precision specifier, it overrides the value given
by the CurrencyDecimals global variable or its TFormatSettings equivalent.
p
Pointer. The argument must be a pointer value. The value is converted to an 8
character string that represents the pointers value in hexadecimal.
s
String. The argument must be a character, a string, or a PChar value. The string or
character is inserted in place of the format specifier. The precision specifier, if present
in the format string, specifies the maximum length of the resulting string. If the
argument is a string that is longer than this maximum, the string is truncated.
x
Hexadecimal. The argument must be an integer value. The value is converted to a
string of hexadecimal digits. If the format string contains a precision specifier, it
indicates that the resulting string must contain at least the specified number of digits;
if the value has fewer digits, the resulting string is left-padded with zeros.
Conversion characters may be specified in uppercase as well as in lowercase—both produce the
same results.
For all floating-point formats, the actual characters used as decimal and thousand separators are
obtained from the DecimalSeparator and ThousandSeparator global variables or their
TFormatSettings equivalent.
Index, width, and precision specifiers can be specified directly using decimal digit string (for
example "%10d"), or indirectly using an asterisk character (for example "%*.*f"). When using an
asterisk, the next argument in the argument list (which must be an integer value) becomes the
value that is actually used.
In addition to standard Delphi number formatting, TAdvStringGrid supports an additional formatting
mode, i.e. the Excel formatting mode. The format mode is selected via grid.FormatType = (ftVCL,
ftExcel). In Excel for example, the number formatting string “$0.00” can be used to format a
number with 2 decimals and a $ prefix.
More information on the Microsoft Excel number formatting can be found at:
http://office.microsoft.com/en-001/excel-help/number-format-codes-HP005198679.aspx
RasterEdge Product Renewal and Update 4. Order email. Our support team will send you the purchase link. HTML5 Viewer for .NET; XDoc.Windows Viewer for .NET; XDoc.Converter for .NET; XDoc.PDF for .NET;
add page number to pdf hyperlink; add url link to pdf
39
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
144 | Page
TAdvStringGrid virtual cells
Through virtual cells, the grid can not only display content that does not have to be stored in grid
Cells but can also apply dynamic transformations of cell contents for display. Virtual cells are
achieved through the OnGetDisplText event that is triggered just before a cell needs to be displayed
or its contents need to be retrieved (like during a print or export) As the cell text is only requested
when it is needed, virtual cells are very fast and efficient. The OnGetDisplText is declared as:
TGetDisplTextEvent = procedure(Sender: TObject; ACol,ARow: Integer; var
Value: string) of object;
The text that needs to be displayed in a cell with coordinates ACol, ARow is set in the Value
parameter.
Example: dynamic HTML formatting of cell text
As it is often inconvenient to set text with HTML tags in the grid itself (for later editing / saving
etc...), the OnGetDisplText is an ideal way for setting only the desired text in the grid cell and
apply formatting only separately for displaying. In this simple example, text is set bold for the first
column by :
procedure TForm1.AdvStringGrid1GetDisplText(Sender: TObject; ACol,ARow:
Integer; var Value: string);
begin
if ACol = 1 then
Value := '<B>' + Value + '</B>';
end;
Example: dynamic number formatting
Suppose that numeric info is stored in the grid cells with a higher precision than required to display.
In this case, the data can be reformatted dynamically with a routine such as :
procedure TForm1.AdvStringGrid1GetDisplText(Sender: TObject; ACol,ARow:
Integer; var Value: string);
var
f: Double;
Err: Integer;
begin
Val(Value,f,Err);
Value := Format('%.2f',[f]);
end;
To display virtual Unicode text in the grid, an equivalent event OnGetDisplWideText is available.
This works identical to OnGetDisplText except that its value parameter is a widestring.
23
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
145 | Page
TAdvStringGrid cell access with column moving
When the option goColMoving is set to true in grid.Options, the user is able to move columns around
at runtime via drag & drop. If programmatic access to cells is necessary in the application, this can
get complex to know in what column a cell can be accessed. Therefore, the grid has built-in
facilities to know the position of a column at any time or to access cells irrespective of the moving
of columns. It is assumed that at startup of the application, the grid has a reference column
ordering. This is the column ordering before a user could have moved columns. Whenever at some
point the grid is reconfigured and a new reference column order should be set, the method
grid.SetColumnOrder can be called. Two functions are provided to find at any time what the
position is of a column or what the original column index is of some column:
Grid.ColumnPosition(OriginalColumnIndex: integer): integer
This function returns the visual column position index of a column that was at startup at index
OriginalColumnIndex.
Grid.ColumnAtPosition(VisualColumnIndex: integer): integer
Returns the original column index of a column found at position VisualColumnIndex.
To access cells irrespective of column moving, the property grid.OriginalCells[Col,Row]: string can
be used. Assuming that the code needs to access information in column 1 and row 1, you can use at
any time grid.OriginalCells[1,1], even when the user moved column 1 to another position in the
grid, the value of the cell can always be set or retrieved with grid.OriginalCells[1,1].
46
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
146 | Page
TAdvStringGrid hints
TAdvStringGrid features a lot of built-in capabilities to display various types of hints.
Regular hints
The hints are enabled by the property grid.ShowHint set to true. The color of the hint window can
be set with the property grid.HintColor. The main hint text is set through the grid.Hint property and
behaves like all hints for VCL components. In addition to this, following hint properties exist:
AnchorHint
When true, the event OnAnchorHint is triggered when the mouse is over a
hyperlink in HTML formatted text. Unless the OnAnchorHint specifies another
hint text, the hint text is by default the value of the anchor.
HintShowCells
When true, a hint is displayed for each cell showing the cell contents. For
each cell, the event OnGridHint is triggered with which a hint text can be set
for the grid cell which coordinates are in the OnGridHint parameter list
HintShowLargeText When true, a hint is displayed for cells containing text that is wider than the
cell width. The hint displays the full text when the mouse is over the cell
HintShowSizing
When true, a hint is displayed during column or row sizing in the grid, showing
the size in pixels of the column or row
ScrollHints
When true, the row index or column index of the scroll position is displayed in
a hint over the scrollbar
For all hints used in the grid, the HTMLHint property setting determines whether HTML tags are
rendered in the hint window or not. By default this is false meaning that any HTML tags in a hint
text are stripped before being displayed.
Example: using hidden cell data to add to a HTML formatted hint text
The grid is filled with flight information in separate cells and in the OnGridHint event, the full flight
information is displayed in the hint whenever the mouse is over the row:
Grid.Cells[0,1] := ‘AA709’;
Grid.Cells[1,1] := ‘American Airlines’;
Grid.Cells[2,1] := ‘New York’;
Grid.Cells[3,1] := ’USA’;
Grid.Cells[4,1] := ’2:00 AM’;
Grid.HideColumn(4);
Grid.ShowHint := True;
Grid.HTMLHint := True;
procedure TForm1.AdvStringGrid1GridHint(Sender: TObject; ARow,
ACol: Integer; var hintstr: String);
begin
hintstr := ‘<B>’+Grid.Cells[0,ARow] +’</B> : ’+ Grid.Cells[1,ARow] +’,
(’+ Grid.Cells[2,ARow]+’ – ‘ + Grid.Cells[3,ARow] + ‘)’ + ‘<FONT
color=”clred”><B>’+ Grid.Cells[4,ARow]+’</B></FONT>’;
26
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
147 | Page
end;
To display a hint with Unicode text, an equivalent event OnGridWideHint is available. This works
identical to OnGridHint except that its hintstr parameter is a widestring.
Important note: in order to have the hint with HTML tags rendered as HTML, it is required to put the
THTMLHint component on the form. The THTMLHint component is included in the TMS Component
Pack Pro and is responsible for the actual HTML formatted rendering of hints.
Office 2007/2010 hints
The grid can also display the richer Office 2007 style hints. This hint consists of a hint title, a hint
picture, multiline hint text and optionally hint help information. The settings for the OfficeHint are
found under grid.OfficeHint. Note that in order to have Office hints with TAdvStringGrid, the
TAdvOfficeHint (available separately or in TMS Component Pack) must be added on the form. The
hint title can be set at design-time via grid.OfficeHint.Title or it can be set dynamically from the
OnGridHint event. In this code snippet, a generic long text is set to show an Office hint like in the
screenshot below:
procedure TForm1.AdvStringGrid1GridHint(Sender: TObject; ARow, ACol:
Integer; var hintstr: string);
begin
AdvStringGrid1.OfficeHint.Title := 'An Office 2007 hint';
hintstr := 'TAdvStringGrid now provides rich Office 2007 style hints for
cells. Any long text can be set dynamically from the OnGridHint
event.';
end;
51
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
148 | Page
TAdvStringGrid search & replace text
Locating in which cell some text can be found is done with the method Find:
function Find(StartCell:TPoint; s:string; FindParams: TFindParams): TPoint;
StartCell contains the cell coordinates where to start the search for the text. If StartCell is equal to
-1,-1 this means the search should start in the first cell of the grid. The parameter s contains the
text to search for and the options for the search are set in the FindParams. When text is found, the
Find function returns the grid coordinates of the cell found, if not the function returns (-1,-1)
FindParams is a set of options that can include:
TFindParameters = (fnMatchCase,fnMatchFull,fnMatchRegular,fnDirectionLeftRight,
fnMatchStart,fnFindInCurrentRow,fnFindInCurrentCol,fnIncludeFixed,fnAutoGoto,
fnIgnoreHTMLTags,fnBackward,fnIncludeHiddenColumns,fnFindInPresetCol,fnFindInPresetRow,fnSel
ectedCells,fnIncludeHiddenRows);
fnAutoGoto
When included, the Find method automatically focuses the cell where
the text is found
fnBackward
When included, search is backwards, i.e. from right to left or from
bottom to top
fnDirectionLeftRight
When included, search is going from left to right cells instead of going
from top to bottom cells first
fnFindInCurrentCol
When included, search happens only in current selected column
fnFindInCurrentRow
When included, search happens only in current selected row
fnFindInPresetCol
When included, search is limited to the column set by public property
grid.FindCol
fnFindInPresetRow
When included, search is limited to the row set by public property
grid.FindRow
fnIgnoreHTMLTags
When included, HTML tags are ignored during the search
fnIncludeFixed
When included, search is also done in the fixed columns
fnIncludeHiddenColumns When included, search is performed in hidden columns as well
fnIncludeHiddenRows
When included, search is performed in rows hidden by closed nodes as
well. When text is found in a row in a closed node and fnAutoGoto is set,
the node will be opened automatically
fnMatchCase
When included, the search is case sensitive
fnMatchFull
When included, the full cell text must be equal to the text searched for
fnMatchRegular
When included, a match expression can be used containing *, ? as well as
greater than or less than specifiers and multiple expressions can be
41
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
149 | Page
combined with AND, OR, NOT
Example:
A* ^ >M : Searches for text starting with A or greater than M
!?A : Text does not have a letter A on second position
fnMatchStart
When included, text searched for needs to match from first character
fnSelectedCells
When included, search is limited to selected cells
Example: searching for all occurrences of a text in the grid
var
Loc: TPoint;
Fp: TFindParams;
begin
Loc := Point(-1,-1);
Fp := [fnMatchRegular, fnAutoGoto];
repeat
Loc := Grid.Find(loc, ‘A*’,fp);
if not ((loc.X = -1) or (loc.Y = -1)) then
ShowMessage(‘Text found at : ‘+IntToStr(loc.x)+’:’+IntToStr(loc.y));
until (loc.X = -1) or (loc.Y = -1);
ShowMessage(‘No more occurrences of text found’);
end;
Note 1:
For searching an empty cell in the grid, the search string that can be used is “”.
Note 2:
For searching a Unicode string, the equivalent method FindWide() is available. In the FindWide
method, the option fnMatchRegular is not supported.
Replacing text can be done in a similar way. The grid provides the method Replace for this with:
grid.Replace(origStr, newStr, FindParams: TFindParams);
The same parameters as for the Find() function are available for the replace. This code snippet will
perform a replace of any cell starting with ‘3’ by ‘A’ in column 2:
AdvStringGrid1.Col := 2;
AdvStringgrid1.Replace('3','A',[fnFindInCurrentCol, fnMatchStart]);
Performing search on multiple columns
Where the Find() function has a single search condition that can be searched for in the entire grid or
part of the grid, an additional function exists: grid.FindMulti(). With grid.FindMulti() a search can be
performed with multiple conditions set for multiple columns.
29
TMS SOFTWARE
TADVSTRINGGRID
DEVELOPERS GUIDE
150 | Page
The functions to do this are declared as:
function FindMulti(Conditions: array of string; Columns: array of integer;
Searchtypes: array of TSearchType; CaseSensitive: array of boolean;
AutoGoto: boolean = false): integer;
function FindMultiNext: integer;
The parameters of FindMulti() are:
Conditions: array of conditions for selected columns
Columns: array of column index values
SearchTypes: array of search condition specifiers
CaseSensitive: array of Boolean values indicating whether the search is case sensitive or not
AutoGoto: when true, the focused row of the grid is automatically set to the first row found
SearchTypes can be:
stStartsWith: cell value starts with search condition
stEndsWith: cell value ends with search condition
stContains: cell value contains search text
stEqual: : cell value is equal to search text
stNotEqual: : cell value is not equal to search text
stNotContains: : cell value does not contain search text
Example:
Assume that a search is needed on value “BMW” in column 1 and value “6” in column 4, then
FindMulti can be used in following way:
AdvstringGrid1.FindMulti(['BMW','6'], [1,4], [stEqual, stEqual],
[false,false], True);
Further matching rows can be searched by calling grid.FindMultiNext: Boolean until this function
returns false.
Documents you may be interested
Documents you may be interested