Title: RE: [DUG]: VB Like Case statement

What about just _pretending_ you had the case statement?!

  function MyCase(AString): boolean;
  begin
    Result := CompareText(AString, myvariable) = 0;
  end;

                                  // select case myvariable
if MyCase('hello') then           // case "Hello"
                                         show_hello
else if MyCase('goodbye') then    // case "goodbye"
                                         show_goodbye
;                                 // end select.


Now every day, just delete a space from the left of show_hello and show_goodbye.  Eventually you'll have converted without even noticing...  :)

Cheers,
Carl

-----Original Message-----
From: Aaron Scott-Boddendijk [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, 15 February 2000 13:12
To: Multiple recipients of list delphi
Subject: Re: [DUG]: VB Like Case statement


> the one thing I DO miss from VB is its case statement which can be a number
> or a string.
>
> i.e. select case myvariable
>        case "Hello"
>            show_hello
>       case "goodbye"
>            show_goodbye
>      end select.
>
> This  has its good and bad points, BUT ofcourse in Delphi it pretty much has
> to me an integer etc.
> Does anyone have any ideas how this could be implemented in Delphi, OR if
> Delphi has a simlilar type of thing....

The best I' can think of is (not for efficiency but for flexibility with
minimal code complexity)...

with TStringList.Create do try
   commatext := 'Hello,Goodbye';
   case IndexOf(MyVariable) of
     0: Show_Hello;
     1: Show_Goodbye;
     else ;
   end;
finally
  free;
end;

Note that there is not reason why the delphi compiler could implement
non-ordinal cases as cascaded 'if' statements... It just that the designers
haven't been nice enough to add that feature...

(now if we had a wishlist for that kind of thing ;))

--
Aaron Scott-Boddendijk
Jump Productions
(07) 838-3371 Voice
(07) 838-3372 Fax


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to