import os
import re
from PIL import Image

def to_delphi_string(s):
    res = []
    in_quote = False
    for ch in s:
        code = ord(ch)
        if code > 127:
            if in_quote:
                res.append("'")
                in_quote = False
            res.append(f'#{code}')
        elif ch == "'":
            if in_quote:
                res.append("''")
            else:
                res.append("''''")
        else:
            if not in_quote:
                res.append("'")
                in_quote = True
            res.append(ch)
    if in_quote:
        res.append("'")
    return ''.join(res)

print("Albarán de Recepción ->", to_delphi_string("Albarán de Recepción"))
print("Gestión de IVA ->", to_delphi_string("Gestión de IVA"))
