You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

73 lines
1.5 KiB

unit uHelperFunctions;
interface
function plaintext(s: string): string;
procedure LogError(FileName, Msg: string);
implementation
uses IOUtils, StrUtils, Math, SysUtils, Forms, IniFiles;
function plaintext(s: string): string;
var
i: integer;
begin
for i := 1 to Length(s) do
begin
case s[i] of
'á', 'à', 'â', 'ä', 'ã':
s[i] := 'a';
'é', 'è', 'ê', 'ë':
s[i] := 'e';
'í', 'ì', 'î', 'ï':
s[i] := 'i';
'ó', 'ò', 'ô', 'ö', 'õ':
s[i] := 'o';
'ú', 'ù', 'û', 'ü':
s[i] := 'u';
'ç':
s[i] := 'c';
'Á', 'À', 'Â', 'Ä', 'Ã':
s[i] := 'A';
'É', 'È', 'Ê', 'Ë':
s[i] := 'E';
'Í', 'Ì', 'Î', 'Ï':
s[i] := 'I';
'Ó', 'Ò', 'Ô', 'Ö', 'Õ':
s[i] := 'O';
'Ú', 'Ù', 'Û', 'Ü':
s[i] := 'U';
'Ç':
s[i] := 'C';
end;
end;
plaintext := s;
end;
procedure LogError(FileName, Msg: string);
begin
try
TFile.AppendAllText(TPath.Combine(ExtractFilePath(Application.ExeName),
Format('%s%s%s', [FileName, FormatDateTime('YYYY-mm-dd', Date), '.log'])),
Format('[ERROR] %s: %s', [FormatDateTime('dd/mm/YYYY hh:mm:ss:zzz', Now),
Msg + sLineBreak]), TEncoding.UTF8);
except
TFile.AppendAllText(TPath.Combine(ExtractFilePath(Application.ExeName),
Format('ErroLog%s%s%s', [FileName, FormatDateTime('YYYY-mm-dd', Date),
'.log'])), Format('[ERROR] %s: %s',
[FormatDateTime('dd/mm/YYYY hh:mm:ss:zzz', Now), Msg + sLineBreak]),
TEncoding.UTF8);
end;
end;
end.