Jump to content


Photo

fkMaximum, fkMinimum result is incorrect

NextGrid6

  • Please log in to reply
3 replies to this topic

#1 axiong

axiong
  • Members
  • 2 posts

Posted 05 July 2025 - 04:53 AM

Windows10, Delphi 12.3 , NextGrid 6.40.

Foot.FormulaKind is fkMaximum or fkMinimum .  the result is incorrect.

and i don't know how to focus on the specific cell.  

 

 

Thanks!

Attached Files



#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,249 posts
  • Gender:Male

Posted 05 July 2025 - 05:51 PM

Hello,

 

I think that I have almost fixed it. I have a problem with value 0, so I decided to use NaN instead.

 

I think I will send the fix at the end of the day. Thank you for your demo project, it really helped.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,249 posts
  • Gender:Male

Posted 05 July 2025 - 10:49 PM

Hello Sir,

 

Please replace this method in full (copy and paste the code). It is located in NxCustomGrid6.pas under Sources\Next Grid

 

procedure TNxCustomGrid6.Recalculate;
var
  Count, i: Integer;
  CaltulatedValue: Double;
 
  function SumCol(Index: Integer): Extended;
  var
    i: Integer;
  begin
    Result := 0;
    for i := 0 to Pred(RowCount) do
    begin
      if (roExcludeInvisible in FCalculateOptions)
        or Row[i].Visible then Result := Result + Cell[Index, i].AsFloat;
    end;
  end;
 
  function CalcCol(Index: Integer; Kind: TNxFormulaKind): Extended;
  var
    i: Integer;
    Value: Double;
    s: WideString;
    sl: TStringList;
  begin
    case Kind of
      fkMaximum, fkMinimum: Value := NaN
      else Value := 0;
    end;
 
    case Kind of
      fkAverage: Value := SumCol(Index) / Count;
      fkCount: Value := Count;
      fkShowingCount: Value := ShowingCount;
 
      { Loop trough all and call OnCalculate }
      fkCustom:
        for i := 0 to Pred(RowCount) do
          if (not (roExcludeInvisible in FCalculateOptions) or Row[i].Visible)
            and CanCalculate(i) then
            begin
              Columns[Index].DoCellCalculate(Index, i, Value);
            end;
 
      fkDistinct:
      begin
        sl := TStringList.Create;
        for i := 0 to RowCount - 1 do
          if (not (roExcludeInvisible in FCalculateOptions) or Row[i].Visible) { visible only }
            and CanCalculate(i) then
          begin
            s := Cells[Index, i];
            if sl.IndexOf(s) = -1 then
            sl.Add(s);
          end;
        Value := sl.Count;
        FreeAndNil(sl);
      end;
 
      fkMaximum:
        for i := 0 to Pred(RowCount) do
          if (not (roExcludeInvisible in FCalculateOptions) or Row[i].Visible)
            and CanCalculate(i)
              and ((Cell[Index, i].AsFloat > Value) or IsNan(Value))
                then Value := Cell[Index, i].AsFloat;
 
      fkMinimum:
        for i := 0 to Pred(RowCount) do
          if (not (roExcludeInvisible in FCalculateOptions) or Row[i].Visible)
            and CanCalculate(i)
              and ((Cell[Index, i].AsFloat < Value) or IsNan(Value))
                then Value := Cell[Index, i].AsFloat;
 
      fkSum: Value := SumCol(Index);
    end;
 
    { Done }
    Result := Value;
  end;
 
begin
  Count := RowCount;
 
  for i := 0 to Pred(Columns.Count) do
    with Columns[i].Footer do
    begin
      CaltulatedValue := CalcCol(i, FormulaKind);
 
      { Trigger event }
      Columns[i].DoCalculated(i, CaltulatedValue);
 
      { Trigger event of the Grid }
      DoFooterCalculated(i, CaltulatedValue);
 
      Value := CaltulatedValue;
    end;
 
  WritelnDebug('Recalculate');
end;

boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#4 axiong

axiong
  • Members
  • 2 posts

Posted 06 July 2025 - 03:54 AM

Thanks!smile.png

 

    Grid1.SelectCell(1,1) ;
    Grid1.SetFocus;






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users