2
I’m having a problem with an example where I need to add a Text
at the ListView
which comes from an XML by code but does not appear when executed. Runs, but appears some warnings depreciation 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;
No, how do I create an Itemobject.Age type item via code? Apparently you’re not creating. For example, there is Item, Detail but Age is not, and I want to create, receive this age and add it to Listview.
– Filipe
Filipe, to add a new field, do not use the "Updateobjects" event. You need to fire this from somewhere else, like a click on a button. Then you loop your listview and add the new Text. Ex: for i := 0 to listview.Items.Count - 1 of Begin txt := Tlistitemtext.Create(listview.Items[i]); txt.Text := 'abc'; ... end;
– Heber
@Heber put this example in the answer. Without formatting for code it is difficult for the Filipe user to use this example correctly, if you want to emphasize it in the answer use [EDIT].
– Paz
@Peace did not understand.. the code is formatted in the answer.
– Heber