On Sun, 23 Jul 2017, Bart wrote:

On 7/23/17, Michael Van Canneyt <mich...@freepascal.org> wrote:

Can you refactor the huge case to use a local proc?
it hurts my eyes...

Yes I can.
But obviously it will keep hurting your eyes, but just in a different
place in the sourcecode?

I meant something like:

  Procedure rgb(r,g,b : word);

  begin
    FPColor.Red:=R;
    FPColor.Blue:=B;
    FPColor.Green:=G;
    Result:=True;
  end;

begin
   // some code
   case LowerCase(S) of
     'white':  RGB($FF,$FF,$FF);
     'silver' : RGB($c0;$c0,$c0);
     // etc
   end;

Is IMHO infinitely more readable. I cherish the hope I am not alone in this?

If you're worried about speed, add inline; but I think the case statement is
inefficient enough not to worry about an additional call.

Michael.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to