Firemonkey: Add child control to TListViewItem at run time


I am attempting to add a TEdit control to a TListView control during run time. I want to parent the TEdit control to the selected TListViewItem belonging to my TListView, however, I cannot find a way to do this.

Originally, I tried this:

TEdit * MyEdit = new TEdit( this );
MyEdit->Parent = MyListView->Selected;

However, this gives me the following error:

[bcc32 Error] E2034 Cannot convert ‘TListViewItem *’ to ‘TFmxObject *’

On a whim, I attempted to typecast the selected item on my list view as a TFmxObject like so:

MyEdit->Parent = (TFmxObject *)MyListView->Selected;

While this compiled, this caused an access violation at run time.

I have searched through a lot of documentation and forum posts and cannot find very much information about dynamically adding a control to a list view item in code. I have seen solutions which propose using the style editor, but I want to avoid that if at all possible.

How can I set the parent of a control to an item in my TListView? Is there a better / more proper way to add controls to a TListViewItem during runtime?

Comments are closed.