0
votes

I've customised the style of a Firmeonkey list box item in such a way that now it can consist of 4 TLables in it. Each of the lable has Alignment as alNone. I'm setting position of each of them in my code whenever i need to add any item. I've observed that when my list has scroll bar and if first component is not visible (i.e. i've scrolled down enough) at that time if i re-add all the items again in list box, then the position of TLabels in first items (or items which are not shown) get distorted.

For setting positions I am using below code :

    (tmpListBoxItem.FindStyleResource('txtCol2') As TLabel).Position.X  :=
    (tmpListBoxItem.FindStyleResource('txtCol2') As TLabel).Position.X  +      (tmpListBoxItem.FindStyleResource('txtCol2') As TLabel).Width;

Any suggesstions, how can i overcome this issue.

Regards, Padam Jain

1

1 Answers

0
votes

Firemonkey styles are repeatedly 'applied' and 'freed' as components appear and disappear from screen.

It is not enough to simply set properties of style objects once and expect those values to be remembered. What you need to do is either listen to the OnApplyStyleLookup event or override the ApplyStyle method of a custom component and use the same you have above to set the properties again.

This means you'll need somewhere to store the values you are going to set.

I would suggest for your situation that you subclass TListBoxItem so you can add suitable properties or fields and put your code in ApplyStyle.