+ Reply to Thread
Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Arethusa

Thread: case of or

  1. #1
    Senior Member cracksman's Avatar
    Join Date
    Dec 2006
    Location
    behind your little sister
    Posts
    1,611

    case of or

    why can't you jump to a "x OR y"? in this case?
    Code:
    var
      I : Integer;
    begin
      I := 0;
      case I of
        0 OR 1: MessageBox(0, '0 OR 1', 'info', 0);//why doesn't this work?
        else MessageBox(0, 'Will fail :)', 'info', 0);
    end;
    explain the first problem before continuing, please.
    I also noticed strange behavior while fucking around, can anyone explain?
    Code:
    var
      I : Integer;
    begin
     I := 0 OR 1;
      case I of
        0 OR 1: MessageBox(0, '"I := 0 OR 1;" ?)', 'info', 0);
        else MessageBox(0, 'Should Not Fail.', 'info', 0);
      end;
    End
    Code:
    var
      I : Integer;
    begin
      I := 0;
      case I of
        0..1: MessageBox(0, '0..1', 'info', 0);
        else MessageBox(0, 'Should Not Fail.', 'info', 0);
      end;
    End;
    Code:
    var
      I : Integer;
    begin
      I := 0 OR 1;
      case I of
        0..1: MessageBox(0, 'I := 0 or 1; 0..1 (also works with 0, 1):', 'info', 0);
        else MessageBox(0, 'Should Not Fail.', 'info', 0);
      end;
    Code:
    var
      I : Integer;
    begin
      I := 0;
      case I of
        0, 1: MessageBox(0, '0, 1 (comma wtf?)', 'info', 0);
        else MessageBox(0, 'Should Not Fail.', 'info', 0);
      end;
    End;
    Last edited by cracksman; 21-02-2012 at 00:29. Reason: added red for easy viewing
    I Retired. stop asking me questions. you can find me on msn or ic0de.

  2. #2
    Junior Member
    Join Date
    Nov 2010
    Posts
    18
    The problem with 0 or 1 is, that you can only have ordinal-values as "case"-values. So "0 or 1" in the case-statement is a binary operation, which has the result of 1. So it would only work if you set i to 1 (or to "0 or 1", which is equal 1).
    When you set i:=0 or 1, i is 1, because it's a binary operation too. So the value stored in i is 1.
    Hope this helps a bit.
    cracksman likes this.

  3. #3
    Senior Member cracksman's Avatar
    Join Date
    Dec 2006
    Location
    behind your little sister
    Posts
    1,611
    ah! perfect explanation.
    I Retired. stop asking me questions. you can find me on msn or ic0de.

  4. #4
    Senior Member
    Join Date
    Apr 2009
    Posts
    300
    ASM explanation:
    A switch is implemented like that
    Code:
    lea eax, [i * 4 + 0x12345678]
    jmp eax
    Now at 0x1245678 there would be the address of the code for the first case.
    At 0x124567C there would be the address of the code for the second case.
    At 0x1245680 ...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [PDF] The Case of TDL3
    By iBm in forum Tutorials and Articles
    Replies: 4
    Last Post: 16-08-2010, 01:30
  2. Replies: 3
    Last Post: 28-08-2009, 13:15
  3. Case
    By mjrod5 in forum Delphi Help
    Replies: 6
    Last Post: 01-02-2009, 04:15
  4. Case Help
    By BlindingDarkness in forum Delphi Help
    Replies: 2
    Last Post: 01-12-2007, 00:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.