Question

I want to change the alignment of a litboxitem that is creatd at runtim and added to a simple listbox.

  • If you add a listview item in the design window before runtime, you can easily adjust the alignment by:

listboxitem1.VertTextAlign := TTextAlign.taTrailing;
listboxitem1.TextAlign := TTextAlign.taCenter;
  • However when the object is created during runtime it simply does not work that way. While the height for instance does:

listboxitem2 := Tlistboxitem.Create(self);
listboxitem2.Text := 'itemtext';
listboxitem2.Height := 100;
listboxitem2.VertTextAlign := TTextAlign.taTrailing;
listboxitem2.TextAlign := TTextAlign.taCenter;
listboxitem2.Name := 'itemname';
listbox1.AddObject(listboxitem2);

What is wrong about this code?

Was it helpful?

Solution

Settings such as this are normally pulled from the style. The StyledSettings property tells FM which properties should be pulled from the style, others will be set from properties. If you edit a property at design time the editor will adjust the StyledSettings property for you. At run time you need to do that manually.

Try adding:

listboxitem2.StyledSettings := listboxitem2.StyledSettings - [TStyledSetting.ssOther];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top