How to customize ListView at runtime?

2

I'm having a problem in an example where I need to add a Text to ListView that comes from one XML per code but does not show up when I run. Wheel, but some warnings appears and the field does not appear. See below:

procedure TfrmUFC.LinkFillControlToField1FillingListItem(Sender: TObject;
  const AEditor: IBindListEditorItem);
var
   Item: TListViewItem;
   TextoIdade: TListItemText;
   TextField: TField;
begin
   Item := lvwLutadores.Items[AEditor.CurrentIndex];
   TextoIdade := Item.Objects.FindObject('Idade') as TListItemText;
   TextField := BindSourceDB1.DataSet.FindField('Idade');
   TextoIdade.Text := TextField.AsString;
end;

Warning :

[dcc32 Warning] uUFC.pas(48): W1000 Symbol 'FindObject' is deprecated: 'Use FindDrawable'

Configs of Text :

procedure TfrmUFC.lvwLutadoresUpdateObjects(const Sender: TObject;
  const AItem: TListViewItem);
var
  TextoIdade: TListItemText;
begin
  TextoIdade := TListItemText.Create(AItem);
  TextoIdade.Name := 'Idade';
  TextoIdade.Align := TListItemAlign.Trailing;
  TextoIdade.VertAlign := TListItemAlign.Center;
  TextoIdade.TextAlign := TTextAlign.Center;
  TextoIdade.PlaceOffset.X := -80;
  TextoIdade.PlaceOffset.Y := 0;
  TextoIdade.Font.Size := 13;
  TextoIdade.Width := 35;
  TextoIdade.Height := 18;
  TextoIdade.Visible := True;
end;
    
asked by anonymous 22.03.2017 / 15:07

2 answers

0

Does he find the text area of the item? Try using something like this:

ListView1.Items[0].Objects.TextObject.Text := BindSourceDB.DataSet.FieldByName('IDADE').AsString;
    
23.03.2017 / 20:58
0

Philip,

Regarding Compiler Warning, "FindDrawable" is used when you already have the Text component on the screen and you want to get it to change some property. Ex:

TListItemTextButton(Aitem.Objects.FindDrawable('Btn1')).Text = 'xxxx';

Not your case, you can ignore this warning.

Looking at your code, the command below causes your object to be off screen:

PlaceOffset.X := -80;

Try this:

PlaceOffset.X := 0;

Another detail, you need to set the Text property to leave something written on the screen:

TextoIdade.Text := 'Agora Vai!';
    
23.03.2017 / 21:32