Search code examples
firemonkeyc++builder-10.2-tokyo

Add Header to TListView in c++ (firemonkey)


It is easy to find examples to add a Header item to a TListView in Delphi. I'm having no luck finding such for c++. I'm trying to translate this code from Object Pas to c++ but I can't figure out a translation for the "Purpose.Header".

with ListView1.Items.Add do
    begin
      Text := Format('Header %d', [Group]);
      Purpose := TListItemPurpose.Header;
    end;

In c++ I have this:

ListView1->BeginUpdate();
TListViewItem* item = ListView1->Items->Add();
item->Purpose = ??????????  // this is the line I need syntax for
item->Text = "My Header";
ListView1->EndUpdate();

Solution

  • TListItemPurpose is an enum type. FireMonkey is compiled with scoped enums enabled (strongly typed enums in C++11 and later).

    The Delphi code you showed translates to C++ as follows:

    TListViewItem *Item = ListView1->Items->Add();
    Item->Text = Format(L"Header %d", ARRAYOFCONST(( Group )));
    Item->Purpose = TListItemPurpose::Header;