Hi
How add header and footer programmatically? For header I found pascal code:
Adding headers to TListView programmatically
How translate this code for header and footer?
Thanks.
Moderator: 2ffat
// NOTE: you should use the Form's constructor instead of the OnCreate event...
void __fastcall TListViewHeaders::FormCreate(TObject *Sender)
{
for (int Group = 1; Group <= 4; ++i)
{
TListViewItem *pItem = ListView1->Items->Add();
pItem->Text = Format(_D("Header %d"), ARRAYOFCONST(( Group )) );
pItem->Purpose = TListItemPurpose::Header;
for (int Item = 1; Item <= 10; ++Item)
ListView1->Items->Add()->Text = Format(_D("Regular item %d.%d"), ARRAYOFCONST(( Group, Item )));
}
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
for (int Group = 1; Group <= 10; ++Group)
{
TListViewItem *pItem = ListView1->Items->Add();
pItem->Text = Format(_D("Header %d"), ARRAYOFCONST(( Group )) );
pItem->Purpose = TListItemPurpose::Header;
ListView1->Items->Add()->Text = Format(_D("Regular item %d.%d"), ARRAYOFCONST(( Group, Group )));
TListViewItem *pItem2 = ListView1->Items->Add();
pItem2->Text = Format(_D("Footer %d"), ARRAYOFCONST(( Group )) );
pItem2->Purpose = TListItemPurpose::Footer;
}
}
// This software is Copyright (c) 2015 Embarcadero Technologies, Inc.
// You may only use this software if you are an authorized licensee
// of an Embarcadero developer tools product.
// This software is considered a Redistributable as defined under
// the software license agreement that comes with the Embarcadero Products
// and is subject to that software license agreement.
//---------------------------------------------------------------------------
#include <fmx.h>
#include <algorithm>
#include <list>
#pragma hdrstop
#include "ListViewCheckListForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
#pragma resource ("*.LgXhdpiPh.fmx", _PLAT_ANDROID)
TForm2 *Form2;
std::list<int> FChecked;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
for (int Group = 1; Group <= 10; ++Group)
{
TListViewItem *pItem = ListView1->Items->Add();
pItem->Text = Format(_D("Header %d"), ARRAYOFCONST(( Group )) );
pItem->Purpose = TListItemPurpose::Header;
ListView1->Items->Add()->Text = Format(_D("Regular item %d.%d"), ARRAYOFCONST(( Group, Group )));
TListViewItem *pItem2 = ListView1->Items->Add();
pItem2->Text = Format(_D("Footer %d"), ARRAYOFCONST(( Group )) );
pItem2->Purpose = TListItemPurpose::Footer;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ListView1ItemClick(const TObject *Sender, const TListViewItem *AItem)
{
// Toggle visibility of accessory when item is clicked
// Save checked state of item
int _index = (const_cast<TListViewItem*>(AItem))->Index;
if ((const_cast<TListViewItem*>(AItem))->Objects->AccessoryObject->Visible)
{
(const_cast<TListViewItem*>(AItem))->Objects->AccessoryObject->Visible = false;
FChecked.remove(_index);
}
else
{
(const_cast<TListViewItem*>(AItem))->Objects->AccessoryObject->Visible = true;
FChecked.push_back(_index);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ListView1UpdateObjects(const TObject *Sender, const TListViewItem *AItem)
{
// In order for text to be truncated properly, shorten text object
TListViewItem::TListViewItemObjects * _objects = (const_cast<TListViewItem*>(AItem))->Objects;
_objects->TextObject->Width = _objects->TextObject->Width - (5 + _objects->AccessoryObject->Width);
// Restore checked state when device is rotated.
// When listview is resized because of rotation, accessory properties will be reset to default values
if(!FChecked.empty()){
std::list<int>::iterator it = std::find(FChecked.begin(), FChecked.end(), (const_cast<TListViewItem*>(AItem))->Index);
if(it != FChecked.end()) {
_objects->AccessoryObject->Visible = true;
} else {
_objects->AccessoryObject->Visible = false;
}
}
}
//---------------------------------------------------------------------------
Lena wrote:Thank You very much!
I get AV in event ListView1UpdateObjects. I'm testing in Windows.
If I comment event ListView1UpdateObjects AV disappears.
How fix it?
I can't answer that, especially since you didn't indicate which line of code is crashing. You will just have to debug the code for yourself.
But why are you using a std::list to keep track of checked item indexes?
Lena wrote:I put a breakpoint on the line:
_objects->TextObject->Width = _objects->TextObject->Width - (5 + _objects->AccessoryObject->Width);
After clicking the button F8:
First chance exception at $004052F6. Exception class $C0000005 with message 'access violation at 0x004052f6: read of address 0x00000014'. Process ListViewCheckListProject.exe (4376)
Is _objects set to NULL?
Lena wrote:Is _objects set to NULL?
Not NULL.
What about the OTHER 2 POINTERS
Lena wrote:- Is _objects->TextObject set to NULL? Yes NULL.
- Is _objects->AccessoryObject set to NULL? Yes NULL.
Users browsing this forum: No registered users and 28 guests