Recent

Author Topic: Simplify displaying data in TListView / TTreeView / TVirtualStringTree  (Read 581 times)

CCRDude

  • Hero Member
  • *****
  • Posts: 614
Earlier this year I got sick of repeating the "same" code to display data for every data class I wrote. I wanted it to be as simple as:

Code: Pascal  [Select][+][-]
  1. type
  2.    TData = class
  3.    published
  4.       property Column: string read FColumn;
  5.    end;
  6.    TDataList = class(TObjectList<TData>);
  7. ...
  8.    FDataList: TDataList;
  9. ...
  10. procedure TMyForm.DisplayData;
  11. begin
  12.    ListView1.DisplayItems<TData>(FDataList);
  13.    TreeView1.DisplayItems<TData>(FDataList);
  14.    VirtualStringTree1.DisplayItems<TData>(FDataList);
  15. end;

Generics were my key to implementing this, but the ListView code also supports collections. Rtti and TypInfo allow access to published properties. And thanks to attributes being introduced, I was able to control display format, alternative column titles, image indexes, listview grouping, hierarchical references and more.

If you're interested in simplifying data display as well (and use a compiler version that supports attributes), check https://gitlab.com/ccrdude-pascal/firefly-ovm and give me some feedback :)

 

TinyPortal © 2005-2018