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 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

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer According to your comment: "..I am not sure if I… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Since it is an HTML email, you can easily embed… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Sourceforge can be still browsed by programming language, although it… May 12, 2026 at 1:19 am

Related Questions

Is it possible to determine the type of a local variable at runtime in
Be forewarned: This question seems way more obvious than it actually is. I'd like
I have written a simple brainfuck interpreter in MATLAB script language. It is fed
I suspect that all non-trivial software is likely to experience situations where it hits

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.