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 64k
  • Answers 64k
  • 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
  • added an answer To gain the most benefit from parallelisation, a task should… May 11, 2026 at 10:51 am
  • added an answer You need to link the library most likely, i.e. add… May 11, 2026 at 10:51 am
  • added an answer Simply add the miglayout-3.7-swing.jar to your classpath: javac -classpath /your/path/to/miglayout-3.7-swing.jar… May 11, 2026 at 10:51 am

Related Questions

Can it be known in general whether or not placing a case within a
I know that in the end it, can't be done. But, what are the
I know the file needs to be where the getClass().getResource(filename) can find it, but
Can it be done or the only way is to configure it on IIS?
Can it be assumed a evaluation order of the function parameters when calling it
and can it be configured not to happen? I'm usually finding myself saving a
What is and how can it be used in C#. Can you use the
Can an abstract class have a constructor? If so, how can it be used
Possible Duplicate: .NET windows application, can it be compressed into a single .exe? To
Here is my short implementation of Russian Peasant Multiplication . How can it be

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.