The following code is from Foley & Van Dam:  "Fundamentals of Interactive Computer Graphics"  (found on the net, and converted to Pascal).   It performs the conversion in both directions:

[1] RGB to HSL
      ---------------
procedure TForm1.RGBtoHSL(R,G,B: double; var H,S,L: double);
var
  cmax,cmin,delta : double;
begin
cmax := B;
cmin := B;
if R > cmax then cmax := R;
if G > cmax then cmax := G;
if R < cmin then cmin := R;
if G < cmin then cmin := G;
L := (cmax + cmin)/2.0;
if (cmax=cmin) then 
begin
   S := 0.0;
   H := 0.0;   {actually it's undefined}
end else
begin
  delta := cmax-cmin;
  if (L < 0.5) then S := delta/(cmax+cmin) else S := delta/(2.0-cmax-cmin);
  if (r=cmax) then
    H := (g-b)/delta
  else if (g=cmax) then
    H := 2.0 + (b-r)/delta
  else H := 4.0+(r-g)/delta;
  H := H/6.0;
  if (H < 0.0) then H := H+1;
end;   {if}
end;   {proc}

[2]  HSL to RGB
      -----------------
procedure TForm1.HSLtoRGB(H,S,L: double; var R,G,B: double);
var
  m1,m2 : double;
begin
if (S = 0.0) then
begin
    R := L;
    G := L;
    B := L;
end else
begin
    if (L <= 0.5) then m2 := L*(1.0+S) else m2 := L+S-(L*S);
    m1 := 2.0 * L - m2;
    R := HuetoRGB(m1,m2,H+1.0/3.0);
    G := HuetoRGB(m1,m2,H);
    B := HuetoRGB(m1,m2,H-1.0/3.0);
end; {if}
end; {proc}

function TForm1.HuetoRGB(m1,m2,h: double): double;
begin
if (h < 0) then h := h + 1.0;
if (h > 1) then h := h - 1.0;
if (6.0 * h < 1) then
    result := (m1+(m2-m1)*h*6.0)
else
    if (2.0 * h < 1) then
       result := m2
    else
       if (3.0*h < 2.0) then result := (m1+(m2-m1)*((2.0/3.0)-h)*6.0) else result := m1;
end;   {function}