Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9174235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:43:10+00:00 2026-06-17T16:43:10+00:00

I’m using Delphi XE3 and I’m developing an application to read numerical type cells

  • 0

I’m using Delphi XE3 and I’m developing an application to read numerical type cells from Excel. I’m using TStringGrid for this import.

I already know, how to get them to the string grid, but can’t manage to do any mathmatical functions like in Excel. How do I calculate min, max and average values for selected cell values of my string grid ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:43:11+00:00Added an answer on June 17, 2026 at 4:43 pm

    You can try the following function. It returns the count of numeric values found in the current string grid’s selection. To declared parameters passed to it returns minimum, maximum and average values from the current selection’s numeric values (if there are some):

    uses
      Math;
    
    function CalcStats(AStringGrid: TStringGrid; var AMinValue, AMaxValue,
      AAvgValue: Double): Integer;
    var
      Col, Row, Count: Integer;
      Value, MinValue, MaxValue, AvgValue: Double;
    begin
      Count := 0;
      MinValue := MaxDouble;
      MaxValue := MinDouble;
      AvgValue := 0;
    
      for Col := AStringGrid.Selection.Left to AStringGrid.Selection.Right do
        for Row := AStringGrid.Selection.Top to AStringGrid.Selection.Bottom do
        begin
          if TryStrToFloat(AStringGrid.Cells[Col, Row], Value) then
          begin
            Inc(Count);
            if Value < MinValue then
              MinValue := Value;
            if Value > MaxValue then
              MaxValue := Value;
            AvgValue := AvgValue + Value;
          end;
        end;
    
      Result := Count;
      if Count > 0 then
      begin
        AMinValue := MinValue;
        AMaxValue := MaxValue;
        AAvgValue := AvgValue / Count;
      end;
    end;
    

    Here’s a sample usage:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      MinValue, MaxValue, AvgValue: Double;
    begin
      if CalcStats(StringGrid1, MinValue, MaxValue, AvgValue) > 0 then
        Label1.Caption :=
          'Min. value: ' + FloatToStr(MinValue) + sLineBreak +
          'Max. value: ' + FloatToStr(MaxValue) + sLineBreak +
          'Avg. value: ' + FloatToStr(AvgValue)
      else
        Label1.Caption := 'There is no numeric value in current selection...';
    end;
    

    Another chapter is how to get notification when the selection of a string grid changes. There’s no event nor virtual method for implementing event like OnSelectionChange. But that would be topic for another question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I am using jsonparser to parse data and images obtained from json response. When
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using JSon response to parse title,date content and thumbnail images and place

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.