Sign in Join
Wiki copytemporary

TValueListEditor: what changed

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

OldNewLine
11![](/wiki-images/3/30/Component-TValueListEditor.png) A **TValueListEditor** ![](/wiki-images/1/12/Tvaluelisteditor.png) is a component that provides a box with key-value-pairs that is user editable. It is available from the [[Additional tab]] of the [[Component Palette]]. A TValueListEditor acts similar as two-column [[TStringGrid]].
22
33The key-value-pairs are provided in the property Strings, a TValueListString type.
44
55## Counts and indices
66
77TValueListEditor may have column head or column title row, which is similar to fixed row of TStringGrid. You can set this visible or not by setting doColumnTitles (this is in DisplayOptions) to true or false.
88
99RowCount property is number of rows including title row.
1010
1111There should be always one VISIBLE row except title row, even a blank row in TValueListEditor. So the minimum RowCount is 2 if column titles are visible, and 1 if column titles are not visible.
1212
1313The content of TValueListEditor is stored in its Strings property. When there is only one blank row in the visible TValueListEditor, its Strings.Count=1. But if you call TValueListEditor.Clear, then its Strings.Count becomes 0.
1414
1515So, the number of key-value-pairs is not exactly the same as RowCount. It is the same as Strings.count.
1616
1717Index of currently selected row is returned as property Row (or you may set its value in the program). Assuming that column titles are visible, the index of first row just below column titles is 1.
1818
1919## Miscellanies
2020
2121### function InsertRow(const Key, Value:string;append:boolean): integer;
2222
2323- There is an append parameter. If set true, new row is inserted after current row, not at the end of whole list of pairs.
2424- In order to append a new string at the end of the whole list, users may call TValueListEditor.Strings.Append procedure or TValueListEditor.Strings.Add function. But there is a very tricky issue. When there is only one single empty row (i.e. no key-value pair exist), TValueListEditor.InsertRow will fill in the first blank row. But Strings.Add or Strings.Append will append a new visible row next to the blank row, which results to RowCount=3.
2525- The returned function result value is index within Strings property (zero-based). If column title row is visible, returned value is less than Row property by 1.
2626
2727### Event handlers of OnBeforeSelection and OnSelection
2828
2929When you change row selection, OnBeforeSelection and OnSelection events may be called, if assigned. Procedures are:
3030
31-`    procedure TForm1.ValueListEditorBeforeSelection(Sender: TObject; aCol, aRow: Integer);`\
32-`    procedure TForm1.ValueListEditorSelection(Sender: TObject; aCol, aRow: Integer);`
31+``` pascal
32+ procedure TForm1.ValueListEditorBeforeSelection(Sender: TObject; aCol, aRow: Integer);
33+ procedure TForm1.ValueListEditorSelection(Sender: TObject; aCol, aRow: Integer);
34+```
3335
3436OnBeforeSelection is called first, and then OnSelection is called. This allows uses to do something with focus-losing row, before new row is selected. This feature is provided with many list-related components, including TListView, TTreeView, etc. But in the two procedures above, value of one parameter, aRow is the same, which is indexing newly selected row. It's not possible to do anything with old row with aRow parameter. Instead, users may use Row property, which will index old row.
3537
3638Let's asume that you have changed focus from row 10 to row 4, by clicking on row 4. Value of parameter aRow is 4 (index of newly selected row) in both procedures. But values of ValueListEditor.Row are different. It will return 10 within OnBeforeSelection, and 4 within OnSelection.
3739
3840## See also
3941
4042- [[doc:lcl/valedit/tvaluelisteditor.html|TValueListEditor doc]]
4143- [[TStringGrid]]
4244
4345---
4446*From the Free Pascal wiki, page "TValueListEditor", as it stood on 2022-08-23 after a change by Egsuh, 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).*

Back to history