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 62195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:26:16+00:00 2026-05-10T18:26:16+00:00

Can it be known in general whether or not placing a case within a

  • 0

Can it be known in general whether or not placing a case within a for loop will result in bad assembly. I’m interested mainly in Delphi, but this is an interesting programming question, both in terms of style and performance.

Here are my codez!

   case ResultList.CompareType of   TextCompareType:     begin       LastGoodIndex := -1;       for I := 1 to ResultList.Count -1 do       if (LastGoodIndex = -1) and (not ResultList[I].Indeterminate) then         LastGoodIndex := I       else if not ResultList[I].Indeterminate then       begin         if (StrComp(ResultList[LastGoodIndex].ResultAsText,                      ResultList[I].ResultAsText) > 0)             and (Result  FalseEval) then           Result := TrueEval         else           Result := FalseEval;          LastGoodIndex := I;       end;     end;   end;   NumericCompareType:   begin     //Same as above with a numeric comparison   end;   DateCompareType:   begin     //Same as above with a date comparison   end;   BooleanCompareType:   begin     //Same as above with a boolean comparison   end; 

alternatively I could write

     begin       LastGoodIndex := -1;       for I := 1 to ResultList.Count -1 do       if (LastGoodIndex = -1) and (not ResultList[I].Indeterminate) then         LastGoodIndex := I       else if not ResultList[I].Indeterminate then       begin       case ResultList.CompareType of       TextCompareType:       begin          if (StrComp(ResultList[LastGoodIndex].ResultAsText,                      ResultList[I].ResultAsText) > 0)             and (Result  FalseEval) then            Result := TrueEval          else            Result := FalseEval;          LastGoodIndex := I;       end;       NumericCompareType:       begin        //Same as above with a numeric comparison       end;       DateCompareType:       begin        //Same as above with a date comparison       end;      BooleanCompareType:      begin        //Same as above with a boolean comparison      end;     end;   end;  end; 

I don’t like the second way because I’m asking a question I know the answer to in a for loop and I don’t like the first way because I’m repeating the code I use to figure out which of my objects contain valid information.

Perhaps there is a design pattern someone could suggest that would circumvent this all together.

  • 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. 2026-05-10T18:26:17+00:00Added an answer on May 10, 2026 at 6:26 pm

    Why not using subclasses?

    This saves the use of the case statement.

    TComparer = class  protected   function Compare(const AItem1, AItem2: TItem): Boolean; virtual; abstract; public   procedure DoCompare(ResultList: ...); end;  TTextComparer = class (TComparer) protected   function Compare(const AItem1, AItem2: TItem): Boolean; override; end;  procedure TComparer.DoCompare(ResultList: ...); var   LastGoodIndex, I : Integer; begin    LastGoodIndex := -1;   for I := 1 to ResultList.Count -1 do   if (LastGoodIndex = -1) and (not ResultList[I].Indeterminate) then     LastGoodIndex := I   else if not ResultList[I].Indeterminate then begin     if Compare(ResultList[LastGoodIndex], ResultList[I]) then       Result := TrueEval     else        Result := FalseEval;   end; end;  function TTextComparer.Compare(const AItem1, AItem2: TItem): Boolean;  begin   Result := StrComp(ResultList[LastGoodIndex].ResultAsText,     ResultList[I].ResultAsText) > 0)     end; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any general rules I can use for evaluating whether a modern compiler
I known that with subversion you can attach arbitrary properties to each files. In
If the table id is known – so the table can be obtained with
Its a well known fact that a static method can work only on static
Python language has a well known feature named interactive mode where the interpreter can
Are there any known design principles, best-practices and design patterns that one can follow
For each of the modern browsers are there well known hooks I can tie
I'm not quite sure stackoverflow is a place for such a general question, but
Anyone have any opinions on whether or not IEquatable<T> or IComparable<T> should generally require
This is more of a general design question, but it will be implemented in

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.