function LFToCRLF(S: string): string;
var
  i: Integer;
begin
  while True do
  begin
    i := Pos(#10, S);
    if i = 0 then Break;
    if i = 1 then
      Result := Result + #13#10
    else if S[i-1] = #13 then
      Result := Result + Copy(S, 1, i)
    else
      Result := Result + Copy(S, 1, i-1) + #13#10;
    S := Copy(S, i+1, Length(S));
  end;
  Result := Result + S;
end;

