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

  • Home
  • SEARCH
  • 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 8991979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:51:02+00:00 2026-06-15T22:51:02+00:00

I’m working on a school project where I have 10 textboxes (5 pairs). The

  • 0

I’m working on a school project where I have 10 textboxes (5 pairs).

The idea is that the sum of each pair can at most be “3”. So

[1] [2]

[1] [0]

…

[2] [1]

I figured that checking this during a “onChange” event is too time consuming so I decided to do it with a button which checks all of them. It will throw a showmessage() as soon as any pair does not satisfy the requirement.

Now is there a way to go over each pair and check if their value is less than or equal to three and is NOT negative? I know I can do it manually by writing a big chunk of code, but I would like to keep it as clean as possible.

Thanks!

  • 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-15T22:51:03+00:00Added an answer on June 15, 2026 at 10:51 pm

    Drop ten TEdit controls on a form. Since you have created these manually, you need to make them easily accessible in code, and there is no super-elegant way to do this. But this works:

    In your implementation section, define

    type
      TEditorPair = record
        First,
        Second: TEdit;
      end;
    

    and add a private field FEditors: array[0..4] of TEditorPair; to your form class. And do

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      FEditors[0].First := Edit1;
      FEditors[0].Second := Edit2;
      FEditors[1].First := Edit3;
      FEditors[1].Second := Edit4;
      FEditors[2].First := Edit5;
      FEditors[2].Second := Edit6;
      FEditors[3].First := Edit7;
      FEditors[3].Second := Edit8;
      FEditors[4].First := Edit9;
      FEditors[4].Second := Edit10;
    end;
    

    Now, select all your ten editor controls, and add a common OnChange event to them.

    procedure TForm1.EditorChange(Sender: TObject);
    
      procedure FailPair(PairIndex: integer);
      begin
        FEditors[PairIndex].First.Color := clRed;
        FEditors[PairIndex].Second.Color := clRed;
      end;
    
      procedure PassPair(PairIndex: integer);
      begin
        FEditors[PairIndex].First.Color := clWindow;
        FEditors[PairIndex].Second.Color := clWindow;
      end;
    
    var
      i: Integer;
      n1, n2: integer;
    begin
      for i := 0 to high(FEditors) do
      begin
        if (FEditors[i].First.Text = '') or (FEditors[i].Second.Text = '') then
          Continue;
        if TryStrToInt(FEditors[i].First.Text, n1) and TryStrToInt(FEditors[i].Second.Text, n2) then
          if InRange(n1+n2, 0, 3) then
            PassPair(i)
          else
            FailPair(i)
        else
          FailPair(i);
      end;
    end;
    

    Sample compiled EXE

    If you are in to code golf, the EditorChange procedure can be shortened to

    procedure TForm1.EditorChange(Sender: TObject);
    
      procedure PairFeedback(PairIndex: integer; Pass: boolean);
      const
        Colors: array[boolean] of TColor = (clRed, clWindow);
      begin
        FEditors[PairIndex].First.Color := Colors[Pass];
        FEditors[PairIndex].Second.Color := Colors[Pass];
      end;
    
    var
      i: Integer;
      n1, n2: integer;
    begin
      for i := 0 to high(FEditors) do
      begin
        if (FEditors[i].First.Text = '') or (FEditors[i].Second.Text = '') then
          Continue;
        PairFeedback(i, TryStrToInt(FEditors[i].First.Text, n1) and
          TryStrToInt(FEditors[i].Second.Text, n2) and InRange(n1+n2, 0, 3));
      end;
    end;
    

    where we make use of a couple of ‘tricks’ such as boolean short-circuit (lazy) evaluation.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.