THotLog |
[ Home ] |
Using tags to retrieve or format data |
Tags come into consideration only when using one of the
overloaded definitions of THotLog
"parsing methodes" hLog.Add(...).
Tags are not case sensitive.
Tags are Standalone or inline ones.
2 - Inline tags: format strings |
Inline tags can be used for information retrieval or string formating.
THotLog provides some inline tags to format strings.
This tags can be combined with any other inline tag(s).
{@nnn} // Left alignment {nnn@} // Right alignment {@nnn@} // Center
{@nnn} - Left alignment
Instructs HLParser that "what follows" up to the next
tag or character has to be written at position
nnn in that line. It provides an easy
way to put strings at a precise location.
CARE:
HLog.Add('{@10}Exiting functionXXX.'); // Will ouptput 9 spaces, then the string "Exiting functionXXX." // Thus writting the first letter("E") at position 10 HLog.Add('{@10}Exiting functionXXX :{@35}{hms}'); // Will ouptput 9 spaces, the string "Exiting functionXXX:", // some more spaces to reach the position 34 and // the parsed value of the {hms} tag // {hms} parsed value will start at column 35There is NO space between {@35} and {hms}. HLog writes spaces as found in the HLog.Add parameters.
{nnn@} - Right alignment
Right alignment to a position will be obtained by reversing the position of
the '@'character:
HLog.Add('{25@}Exiting functionXXX.');
-> writes "Exiting functionXXX." at position (25 - length('Exiting functionXXX.')).
{@nnn@} - Center
Centering is obtained by using two "@", one before and one after
the requested length.
"What follows" the tag is centered in a string of lenght will nnn.
It will start at the current position of this line. If an odd number
of spaces has to be added, the extra space will be added after the
string to center.
The important point is that what has to be centerd isn't centered
between the end of the previous string, and the first non-blank character
of the next one, but exclusively related to the length
you pass between the two "@", that is considered to be the
full length of that field.
The examples illustrates that behaviour:
hLog.Add('{ruler+}'); hLog.Add('Left part{@25@}Middle string{}End of the line');results in
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|....| Left part Middle string End of the lineBut
hLog.Add('{ruler+}'); hLog.Add('Left part{@25@}Middle string{@50}End of the line');results in
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|....| Left part Middle string End of the line
hLog.Add('{ruler+}'); HLog.Add('Exiting function{*25.}: ' + 'What you want');looks like
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|....| Exiting function.........: What you want
HLog.Add('{*20.}'); // Will output 20 dots at the beginning of the line: ....................
hLog.Add('{ruler+}'); HLog.Add('{@5}=> Entering function{*35.}: ' + SomeFunctionName + '{60@}({HMS}-{GTC})''{@5}=> Exiting{*35.}: '{60@}({GTC})');Result:
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|....| => Entering function...............: MyFunction (19:21:35-5164171) => Exiting.........................: MyFunction (5173546)
hLog.Add('{ruler+}'); HLog.Add('Exiting{*25.}: ' + SomeFunctionName + '{@30}({GTC})');results in
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|....| Exiting..................: MyFunction (12554877)instead of
Exiting function.........: MyF(12554877)
{&} - Enlarging the visibility range of @ tags
hLog.Add('{ruler+}'); HLog.Add('{@5}-> Entering function{*25.}: ' + SomeFuncName + '{60@}{&}({HMS}-{GTC}){&}'); HLog.Add('{@5}-> Exiting{*25.}: ' + SomeFuncName + '{60@}{&}({GTC}){&}');In the last line above {&} tags are needed again because otherwise only the openning parenthesis would be at position 60.
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|....| -> Entering function.....: MyFunction (19:31:09-5738500) -> Exiting...............: MyFunction (5758312)
hLog.Add('{ruler+}'); hLog.Add('{@10}{*5>}Strings to be written''); // Writes an error: 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|....| #HLTag(@10>>) Strings to be writtenWorkaround:
HLog.Add('{@10}{}{*5>}Strings to be written');
>>>>>Strings to be written
hLog.Add('{ruler+}'); HLog.Add('{*5>}{@30}Strings to be written') // is ok 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|....| >>>>> Strings to be written"String To be written" starts at the wanted byte position of 30
{/} - Inserting carriage return - line feeds
hLog.Add('{ruler+}');procedure TForm1.Button8Click(Sender: TObject); var i: real; s: String; begin Randomize; i := Random; s := TimeToStr(now); hLog.Add('{ruler+}'); hLog.Add(vsNone,['Here are some datas to output exactly like I want {/}', '{@15}This one is number{@40}: ',1, '{/}','{@15}and this one is number{@40}: ',2,'{/}', '{@15}the third one is {@40}: ',3, '{/}', '{/}You can see the whole bunch mixes integers, real, and strings (including tags) whithout problems...','{/}', '{/}By the way, "i" value is{@40}: ', i, '{/}', 'and the time part of "now()" function (',now,') translates to : ',s ]); end; 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|....| Here are some datas to output exactly like I want This one is number : 1 and this one is number : 2 the third one is : 3 You can see the whole bunch mixes integers, real, and strings (including tags) whithout problems... By the way, "i" value is : 0,990934341913089 and the time part of "now()" function (38060,9705908102) translates to : 23:17:39{/} tags can be either part of a string or can be used standalone with the same result.
{{} and {}} - Writting brackets
hLog.Add('The tag {{}hms{}} is now worth {hms}');
The tag {hms} is now worth 21:12:42
THotLog |