Listview Event Error ( Listview1updateobjects ), to show or hide item. ( Delphi firemonkey )

Asked

Viewed 514 times

1

If anyone can help me, I’m having a problem in a method of a ListView, the method is the TForm13.ListView1UpdateObjects in it I do the following procedure: I check the value of an item to decide whether or not to show an item and concateno the item to be shown.

Follows the code:

    procedure TForm13.ListView1UpdateObjects(const Sender: TObject;
  const AItem: TListViewItem);

var
   ItemText_parcelar_cartao : TListItemText;
   ItemText_valor_parc : TListItemText;
   ItemText_quant_parc : TListItemText;
   concat : TListItemText;
begin


    ItemText_parcelar_cartao := AItem.Objects.FindObject('Text_parcelar_cartao') as TListItemText;
    ItemText_valor_parc := AItem.Objects.FindObject('Text_valor_parcela') as TListItemText;
    ItemText_quant_parc := AItem.Objects.FindObject('Text_quant_parcela') as TListItemText;
    concat := AItem.Objects.FindObject('Text_concat') as TListItemText;




    if ItemText_parcelar_cartao.text = 'sim' then
    begin

       concat.visible := true;
       concat.text := 'ou ' + ItemText_quant_parc.text + 'x de ' + ItemText_valor_parc.text;

    end
    else
       concat.visible := false;

end;

The problem is this: this ListView is connected in a FDMemTable main, when I charge FDMemTable with the data initially, everything works fine, and in another step I add more records to the FDMemTable main coming from a FDMemTable auxiliary, with the following function:

FDMemTable_produto_por_desc.AppendData(FDMemTable_produto_por_desc_pagina.Data, true); 

When I add the new records, the function TForm13.ListView1UpdateObjects is executed, and it is at this time that the error occurs, the variable ItemText_parcelar_cartao.text is empty and does not receive the value of the FDMemTable, and therefore it does not test and does not concatenate correctly.

  • Cassiano, and if you try to play the text for a string variable, like this: str := AItem.Objects.FindObject('Text_parcelar_cartao').asString; It would come the value correctly without having to move to a type variable TListItemText, but yes directly to a string?

  • Or else ... AItem.Objects.FindObject('Text_parcelar_cartao').Text;. The idea is to find the object already picking the string located.

  • Ok... Rodrigo, I did : str_parc := Tlistitemtext(Aitem.Objects.Findobject('Text_parcelar_cartao')). Text; yes . direct text does not work , but did not solve the problem, the variable remains empty.

3 answers

0

The problem is this: this Listview is connected in a main Fdmemtable, when I load the Fdmemtable with the data initially, everything works fine, and in another step I add more records to the main Fdmemtable coming from an auxiliary Fdmemtable,

Connected how? Livebindings? If it is takes off this mooring and updates via code

Your code itself has no logical problems, theoretically if there is no value for the variable ItemText_parcelar_cartao.Text, It will simply remain hidden. Since you reported that after Fdmemtable’s Append that is giving the problem, I believe the blame is before throwing the dice on the list. If you use Livebindings will get problem all the time.

0

Hello I would try to use the value as a condition or move to another variable other than Tlistitemtext. Use Listitemtext only to display results and not as a condition.

0

Hello. Try this way to get the value.

var
  item: TListItemText;

begin
  item := AItem.Objects.FindObjectT<TListItemText>('Text_parcelar_cartao');

end;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.