With the code below I can create a button inside a listview item but when I click on the button it causes an error, any ideas to solve it, apparently it could be because I am not able to add a relative to the button.
procedure TForm1.btAddClick(Sender: TObject);
var
item : TListItemText;
AItem: TListViewItem;
begin
AItem := ListView1.Items.AddItem;
end;
procedure TForm1.ListView1UpdateObjects(const Sender: TObject; const AItem: TListViewItem);
begin
if AItem.Objects.FindObject('MyButtonCustom') = nil then
begin
Create_BT(AItem);
end;
end;
procedure TForm1.Create_BT(const AItem: TListViewItem);
var
LItem: TListItemTextButton;
begin
LItem := TListItemTextButton.Create(nil);
AItem.BeginUpdate;
LItem.Name := 'MyButtonCustom';
LItem.Text := 'MyButtonCustom';
LItem.Height := 20;
LItem.Width := 200;
LItem.PlaceOffset.X := 0;
LItem.PlaceOffset.X := 0;
LItem.Align := TListItemAlign.Center;
LItem.VertAlign := TListItemAlign.Center;
LItem.TextAlign := TTextAlign.Center;
LItem.TextVertAlign := TTextAlign.Center;
AItem.EndUpdate;
AItem.Objects.Add(LItem);
end;
This is the error that I receive (copied from comments by @tobya)
LItem := TListItemTextButton.Create(nil)
When clicking on the button that was created, the following errors appear:
raised exception class $C0000005 with message 'access violation at 0x00a85323: read of address 0x00000000.' Access violation at address 00A85323 in module 'Project1.exe' (offset 575323). Read of address 00000000. LItem := TListItemTextButton.Create(AItem);
closing the form causes the errors:
Project Project.exe raised exception class EInvalidPointer with message 'Invalid point operation'. Exception EInvalidPointer in module Project1.exe at 000085CD Invalid pointer operation.

AItem.Objects.Add()does, but I suspect that it might add a parent but not an owner. Have you triedLItem:=TListItemTextButton.Create(AItem)?