Lazarus

Programming => LCL => Topic started by: Pe3s on July 04, 2022, 11:10:02 am

Title: [SOLVED] ListView column summation
Post by: Pe3s on July 04, 2022, 11:10:02 am
How can I fix the code to sum a column

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var i: Integer;
  3.   item: TListItem;
  4. begin
  5.   for i := 0 to ListView1.Items.Count do
  6.   begin
  7.     i:= Item.SubItems[2];
  8.  
  9.   end;
  10. end;
  11.  

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var i: Integer;
  3.   item: TListItem;
  4. begin
  5.   for i := 0 to ListView1.Items.Count -1 do
  6.   begin
  7.     ListView1.Items[i].SubItems[2];
  8.     Form1.Caption := IntToStr(i);
  9.   end;
  10. end;  
  11.  
Title: Re: listview column summation
Post by: howardpc on July 04, 2022, 11:18:32 am
In English a petrel is any bird of the genus Procellaria, so named from the observation that with its webbed feet it appears to be able to walk on water (see the story about Peter in the gospel of Matthew 14:29).
Can you try an alternative translation engine so we know what you mean by "petrel"?
Title: Re: listview column summation
Post by: Zvoni on July 04, 2022, 12:25:25 pm
How can I sum columns in a listview.
By hand.....
Title: Re: listview column summation
Post by: Pe3s on July 04, 2022, 05:47:39 pm
 :D
Title: Re: ListView column summation
Post by: ASerge on July 04, 2022, 09:38:24 pm
How can I fix the code to sum a column
Code: Pascal  [Select][+][-]
  1. procedure TForm2.Button1Click(Sender: TObject);
  2. var
  3.   Item: TListItem;
  4.   Sum: SizeInt = 0;
  5. begin
  6.   for Item in ListView1.Items do
  7.     Inc(Sum, Item.SubItems[2].ToInteger);
  8.   Caption := Sum.ToString;
  9. end;
Title: Re: ListView column summation
Post by: Pe3s on July 05, 2022, 08:17:55 am
What the code that sums up columns with time in hh: nn formatting looks like ?
Code: Pascal  [Select][+][-]
  1.     procedure TForm2.Button1Click(Sender: TObject);
  2.     var
  3.       Item: TListItem;
  4.       Sum: TTime = 0;
  5.     begin
  6.       for Item in ListView1.Items do
  7.         Sum += Item.SubItems[2].ToInteger;
  8.       Caption := FormatDateTime('hh:nn', Sum);
  9.     end;
  10.  
Title: Re: ListView column summation
Post by: ASerge on July 05, 2022, 09:24:00 pm
What the code that sums up columns with time in hh: nn formatting looks like ?
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   Item: TListItem;
  4.   Sum: TDateTime = 0;
  5.   Time: TDateTime;
  6. begin
  7.   for Item in ListView1.Items do
  8.     if TryStrToTime(Item.SubItems[2], Time) then
  9.       Sum += Time;
  10.   Caption := FormatDateTime('hh:nn', Sum);
  11. end;
Title: Re: ListView column summation
Post by: wp on July 06, 2022, 01:01:44 am
Since the sum can become larger than a day I'd rather use the square bracket symbol and the fdoInterval option in FormatDateTime:
Code: Pascal  [Select][+][-]
  1.  Caption := FormatDateTime('[hh]:nn', sum, [fdoInterval]);
Title: Re: ListView column summation
Post by: Pe3s on July 07, 2022, 07:11:33 pm
Thank you very much for help  :)
TinyPortal © 2005-2018