Sign in Join
Wiki copytemporary

IDE Window: IDE Options - Debugger Value-Formatter: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11> **Note:** This page applies to Lazarus 3.99
22
33![](/wiki-images/3/38/ValueFormatters-List.png)
44
55__toc__
66
77# About Value-Formatter
88
99Value-Formatter change the format in which a value is displayed.
1010
1111They do not affect the content. The underlying data retrieved from the debugged process is not affected by a value formatter. Value formatter can only change the presentation of that data. This can range from formatting (spacing, line breaking, quoting), over simple conversion (decimal/hex or float-as-date) to performing calculations/lookups on/with the data.
1212
1313Value formatters can act on the entire result of a watched value, including the entire structure or array. Or they can act on individual entries/fields.
1414
1515# General Configuration
1616
1717## Search Order
1818
1919A value can only be formatted by one formatter. In case of a structure or array, that can mean each field is a value that can be formatted.
2020
2121The IDE needs to find decide which Value-Formatter to use. If several Value-Formatter match their Filter, then the following criteria are used.
2222
2323### Project vs IDE list
2424
2525Value-Formatter can be configured globally for the entire IDE, or for the current project. If enabled, the IDE will first look for a Value-Formatter from the project, and only if none is found it will look for a Value-Formatter from the IDE config.
2626
2727In the Project settings it is possible to enable/disable each of those two lists.\
2828![](/wiki-images/9/93/ValueFormatters-Project.png)
2929
3030"Store Formatter Config in session"
3131The project list of Display-Formatters is stored in the session, rather than the lpi file.\
3232The settings to "store in session" itself remains in the lpi.
3333
3434### Ordering
3535
3636Value-Formatter can be ordered in their list (Up/Down buttons). Each list is searched top to bottom for the first match.
3737
3838### Checked (Enabled) or direct selection (watch properties)
3939
4040Each Value-Formatter has a checkbox. The IDE will only apply enabled/active Value-Formatter automatically (if they match).
4141
4242Non active Value-Formatter will be ignored by default. They can be manually applied to an individual watch (or in the inspect/evaluate windows). For this the watch properties have a drop down that allows to select a Value-Formatter. From this list active and non-active Value-Formatter can be selected. Please note, that selected Value-Formatter must still have matching filter settings. But for non-active Value-Formatter the filters can be set more relaxed to make sure they do match.
4343
4444## Adding / Removing
4545
4646To add a new Value-Formatter, first select it from the drop down. Then press "Add".
4747
4848## Filters
4949
5050Some Value-Formatter have build in filters. Such as a Value-Formatter that takes a number as input will only work on values of numeric type. If you are watching a structure or array the Value-Formatter can however act on matching entries/fields.
5151
5252### Match type by name
5353
5454You must specify which data type or types the Value-Formatter should be applied to. At least one value must be given. You can specify more than one type, by adding one one each line. In this case at least one must be matched.
5555
5656This can be the exact name of a type: boolean, word, TForm (leading or trailing spaces will be ignored)
5757
5858Or you can match the typename using "*" as placeholder (for zero, one or more characters)
5959
60-` TData*`\
61-` *Ptr`\
62-` T*Foo`\
63-` T*Frame*`
60+```text
61+ TData*
62+ *Ptr
63+ T*Foo
64+ T*Frame*
65+```
6466
6567Any amount of * can be used.
6668
6769For class types inheritance can be checked by starting a line with "is:"
6870
69-`  is:TControl`\
70-`  is:TCustom*`\
71-`  is:*Form `
71+```text
72+ is:TControl
73+ is:TCustom*
74+ is:*Form
75+```
7276
7377> **Note:** FPC resolves typenames to their un-aliased form. So "Integer" will be known as "longint" (except on 16bit systems).
7478
7579#### Match the variable name or expression
7680
7781It is also possible to match the name of the variable or field.
7882
7983Lines prefixed with either "var:" or "expr:" will do that.
8084
81-`  var:MyForm`\
82-`  var:*Data`\
83-`  expr:*.SomeField`
85+``` pascal
86+ var:MyForm
87+ var:*Data
88+ expr:*.SomeField
89+```
8490
8591- "var:" will be matched against the term that you entered into the watch "expression" property, or the name of a local, or the identifier in your hint or inspect/evaluate Window.\
8692 If you watch "MyPoint: TPoint" then
8793
8894:* The watch window will display: (X: 123; y: 99)
8995
9096:* If your Value-Formatter is matching the entire structure, then "var:My*" will match "MyPoint"
9197
9298:* If your Value-Formatter is matching each field then for each field the term "MyPoint" will be matched by "var:My*".\
9399But if you tried "var:*X" to match only the X value, then that does not work. The term being matched is "MyPoint"
94100
95101:* if you expand the watch in the watch window, so you have in-lined extra rows for x and y then those extra rows are new watches and their term is "MyPoint.X" or "MyPoint.Y". They will be matched by both "var:My*" or "var:*.X". But they would not be matched by "var:MyPoint" (since there is no * and this is an exact match)
96102
97103
98104
99105- "expr:" will be matched against the var + path-to-field. (Albeit, in a simplified form).\
100106 The same "MyPoint" watch.
101107
102108:* If you are matching fields in the single line view of the watch windows, the fields will have the term "MyPoint.X" (or Y).
103109
104110:* If you are matching fields in the expanded view of the watch windows, the fields will also have the term "MyPoint.X" (or Y).
105111
106112:* Array indexes are omitted
107113
108114If you have a field "MyFoo" on an object, then your watch can either be
109115
110-`  MyObject`\
111-`  MyObject.MyFoo`\
112-`  MyFoo`
116+```text
117+ MyObject
118+ MyObject.MyFoo
119+ MyFoo
120+```
113121
114122The last one, if you are in a method of the object.
115123
116124To match the field in all cases, use the following two:
117125
118-`  expr:*.MyFoo`\
119-`  expr:MyFoo`
126+```text
127+ expr:*.MyFoo
128+ expr:MyFoo
129+```
120130
121131The second could also be "var:MyFoo". The first matches if MyFoo is in the structure. For the watch "MyObject" the IDE will append the ".MyFoo" when displaying the field.
122132
123133Note, if you click the + to expand a watch, then the new watches on the expanded rows may contain a typecast (depending on the watch settings). So the Watch-name to match may be "TMyObject(MyObject).MyFoo". On the other hand the term passed to "expr:" prefixed matches for fields on the non-expanded line does not have such a typecast.
124134
125135> **Note:** When matching the name, there must still be a match for the type. If the type does not matter then specify a standalone "*"
126136
127137### Limit to nest-level
128138
129139If you have structures or arrays, then entries/fields are seen as "nested values".
130140
131141You may have situations were you want to exclude those from being formatted. Then you can set the Min/Max nest-level to 0. (This also saves the IDE the work to perform matching on type names).
132142
133143Or you may only want to have formatting if a value is nested, then set the min-level to 1. (or higher). Note, that
134144
135145- if you specify "MyObject", then the fields are at level 1
136146- If you expand that watch to have individual rows to display each field, then they are at level 0 (top level)
137147- if you enter a watch "MyObject.FieldFoo" then that is at level 0 (top level).
138148
139149The reason is, that if it has a row on its own, it has more space to display, and therefore different handling may be wanted.
140150
141151If your watch is just "FieldFoo" (while in a method of the owning object), then you can not check if this is a field, or what the name of the owning variable is (in this case it would be "self").
142152
143153## Settings
144154
145155### Show original
146156
147157Most Value-Formatter have the option to show the original/unchanged value next to the formatted value.
148158
149159# Available Value-Formatter
150160
151161## Date Time
152162
153163Convert a float to human read-able date/time.
154164
155165You can set the format for the output according to <https://www.freepascal.org/docs-html/rtl/sysutils/formatchars.html>
156166
157167There are 3 fields for specifying a format:
158168
159169- "Date Time" if the value has non-zero parts for date and time
160170- "Date" if the value has a zero part for time
161171- "Time" if the value has a zero part for date
162172
163173By default the IDE comes with 3 instances of the formatter setup, for the data types:
164174
165175- TDateTime
166176- TDate
167177- TTime
168178
169179This means it is possible to set up a different format for a TTime that for some reason has a date part, and a TDateTime which is expected to have a date part.
170180
171181## Color
172182
173183Will lookup the name of the color. Such as "clRed" or "clBlue".
174184
175185Alternatively it can display an RGB list.
176186
177187The color names are looked up from those registered in the IDE. For use with FPC's "FindIntToIdent". If the application registers its own list, that is not taken into account. In such a case consider #Convert_Ordinal_to_name .
178188
179189## Alpha Color
180190
181191As TColor, but for TAlphaColor
182192
183193## CharArray as string
184194
185195For data type
186196
187-`  Array of char`\
188-`  Array [n..m] of char`
197+```text
198+ Array of char
199+ Array [n..m] of char
200+```
189201
190202Displays the data as string. This improves readability over a list of individual chars.
191203
192204The string can be cut at the first \#0.
193205
194206## Custom DisplayFormat
195207
196208Set a specific DisplayFormat. (e.g. Hex or Binary).
197209
198210If you have data types (or fields/variables by name) that you always want in a specific DisplayFormat
199211
200212- The option "Override watch settings"
201213
202214:* If not checked then the DisplayFormat acts as default, but you can choose a different setting in the watch properties
203215
204216:* If checked then the DisplayFormat will override the setting from the watch properties
205217
206218The latter case can be useful if the format is to be applied to some fields in a structure. The settings in the watch properties can then be used for other fields, but the field matched by the Value-Formatter will be forced to the format given here.
207219
208220It can be useful to have 2 Value-Formatters
209221
210222- Min/Max level = 0 (top level) with "Override watch settings" not checked
211223- Min level = 1 (nested) with "Override watch settings" checked
212224
213225## Convert Ordinal to name
214226
215227Find the name for named integer constants.
216228
217229if you have code like
218230
219-` const`\
220-` ecLeft            = 1;    // Move cursor left one char`\
221-` ecRight           = 2;    // Move cursor right one char`\
222-` ecUp              = 3;    // Move cursor up one line`\
223-` ecDown            = 4;    // Move cursor down one line`\
224-` ecWordLeft        = 5;    // Move cursor left one word`\
225-` ecWordRight       = 6;    // Move cursor right one word`
231+``` pascal
232+ const
233+ ecLeft = 1; // Move cursor left one char
234+ ecRight = 2; // Move cursor right one char
235+ ecUp = 3; // Move cursor up one line
236+ ecDown = 4; // Move cursor down one line
237+ ecWordLeft = 5; // Move cursor left one word
238+ ecWordRight = 6; // Move cursor right one word
239+```
226240
227241You can copy that code into the config for the Value-Formatter (it will ignore the comments).
228242
229243It expects
230244
231245- one value per line
232246- NAME = 123
233247- optional comment / optional ; at end
234248- comment are skipped multi-line
235249- NAME=TMyType(123) // TMyType is ignored
236250- NAME=PREVIOUS_NAME + 123 // in that exact order only
237251
238252If the value formatter is applied to a value it will look up the number and print the text.
239253
240254---
241255*From the Free Pascal wiki, page "IDE Window: IDE Options - Debugger Value-Formatter", as it stood on 2024-04-29 after a change by Martin, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
242256Category: Debugging

Back to history