[fpc-devel] HTML string to TFPColor

Michael Van Canneyt michael at freepascal.org
Sun Jul 23 15:25:50 CEST 2017





On Sun, 23 Jul 2017, Bart wrote:

> On 7/23/17, Michael Van Canneyt <michael at 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.



More information about the fpc-devel mailing list