Skip to content

Commit e1f4442

Browse files
committed
- Correções em lclformat
1 parent 283e8c7 commit e1f4442

1 file changed

Lines changed: 24 additions & 32 deletions

File tree

format/lclformat.pas

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
/// //////////////////////////////////////////////////////////////////////////
2-
{
3-
Unit Format
4-
Criação: 99 Coders (Heber Stein Mazutti - heber@99coders.com.br)
5-
Adaptação e melhorias: Mobius One
6-
}
7-
/// //////////////////////////////////////////////////////////////////////////
8-
91
unit LCLFormat;
102

11-
{$IFDEF FPC}
12-
{$codepage UTF8}
13-
{$MODE Delphi}
14-
{$ENDIF}
3+
{$codepage UTF8}
4+
{$MODE Delphi}
5+
{$IFNDEF DEBUG}{$hints off}{$ENDIF}
156

167
interface
178

189
uses
19-
StdCtrls, Classes, DateUtils, Math, SysUtils, TypInfo,
20-
StrUtils;
10+
StdCtrls, Classes, DateUtils, Math, SysUtils, TypInfo, StrUtils;
2111

2212
const
2313
csDigitos = ['0'..'9'];
@@ -27,13 +17,13 @@ interface
2717
csSimbolosMon = ['-', '+', ',', '.'];
2818

2919
// Lazarus issue: set in current version is only 0..254 and can't hold unicode chars
30-
csEspeciais: array of WideChar = ['ã', 'á', 'à', 'â', 'é', 'ê', 'í', 'ó', 'ô',
31-
'õ', 'ú', 'ç', 'Ã', 'Á', 'À', 'Â', 'É', 'Ê', 'Í', 'Ó',
32-
'Õ', 'Ô', 'Ú', 'Ç'];
20+
csEspeciais: array of widechar =
21+
['ã', 'á', 'à', 'â', 'é', 'ê', 'í', 'ó', 'ô', 'õ', 'ú',
22+
'ç', 'Ã', 'Á', 'À', 'Â', 'É', 'Ê', 'Í', 'Ó', 'Õ', 'Ô', 'Ú', 'Ç'];
3323

3424
type
3525
TFormato = (&Date, Bits, CEP, CEST, CFOP, CNH, CNPJ, CNPJorCPF, CPF, CREA,
36-
CRM, Dinheiro, Hora, hhmm, InscricaoEstadual, NCM, OAB, Personalizado, Peso,
26+
CRM, Dinheiro, Hora, HoraCurta, InscricaoEstadual, NCM, OAB, Personalizado, Peso,
3727
Porcentagem, Telefone, TituloEleitor, Valor, VeiculoMercosul,
3828
VeiculoTradicional);
3929

@@ -110,7 +100,7 @@ function TFormatHelper.AlfaNumerico(aStr: string): string;
110100
Result := Result + aStr[C];
111101

112102
for I := 0 to pred(Length(csEspeciais)) do
113-
if aStr[C] = csEspeciais[I] then Result := Result + aStr[C]
103+
if aStr[C] = csEspeciais[I] then Result := Result + aStr[C];
114104
end;
115105
end;
116106

@@ -136,16 +126,17 @@ function TFormatHelper.Decimal(aStr: string; aPrecisao: integer): double;
136126
if aPrecisao < 0 then
137127
aPrecisao := 2;
138128

129+
Result := 0;
139130
try
140131
Valor := '';
141132
for x := 0 to pred(aStr.Length) do
142133
if CharInSet(aStr.Chars[x], csDigitos + [',', '-']) then
143134
Valor := Valor + aStr.Chars[x];
144135

145-
Result := Format('%.' + aPrecisao.ToString + 'f',
146-
[StrToFloatDef(Valor, 0)]).ToDouble;
136+
Result := StrToFloat(Format('%.' + IntToStr(aPrecisao) + 'f',
137+
[StrToFloatDef(Valor, 0)]));
147138
except
148-
Result := Format('%.' + aPrecisao.ToString + 'f', [0]).ToDouble;
139+
Result := StrToFloat(Format('%.' + IntToStr(aPrecisao) + 'f', [0]));
149140
end;
150141
end;
151142

@@ -223,7 +214,7 @@ function TFormatHelper.FormataData(aStr: string): string;
223214
if aStr.Length > 8 then
224215
begin
225216
try
226-
Result := FormatDateTime('dd/mm/yyyy', UnixToDateTime(aStr.ToInt64));
217+
Result := FormatDateTime('dd/mm/yyyy', UnixToDateTime(StrToInt64(aStr)));
227218
except
228219
Result := '';
229220
end;
@@ -251,7 +242,7 @@ function TFormatHelper.FormataData(aStr: string): string;
251242
function TFormatHelper.FormataDinheiro(aStr: string; aPrecisao: integer): string;
252243
begin
253244
try
254-
Result := Format('%.' + aPrecisao.ToString + 'm',
245+
Result := Format('%.' + IntToStr(aPrecisao) + 'm',
255246
[StrToFloatDef(Inteiro(aStr), 0) / Power(10, aPrecisao)]);
256247
except
257248
Result := Format('%.2m', [0]);
@@ -382,9 +373,9 @@ function TFormatHelper.FormataPeso(aStr: string; aSeparador: boolean = False): s
382373
begin
383374
try
384375
if aSeparador then
385-
Result := Format('%.3n', [SomenteNumero(aStr).ToInteger / 1000])
376+
Result := Format('%.3n', [StrToInt(SomenteNumero(aStr)) / 1000])
386377
else
387-
Result := Format('%.3f', [SomenteNumero(aStr).ToInteger / 1000]);
378+
Result := Format('%.3f', [StrToInt(SomenteNumero(aStr)) / 1000]);
388379
except
389380
Result := Format('%.3f', [0]);
390381
end;
@@ -407,7 +398,8 @@ function TFormatHelper.Formatar(Formato: TFormato; Texto: string;
407398
Texto := FormataData(SomenteNumero(Texto));
408399

409400
Bits:
410-
Texto := FormataBits(SomenteNumero(Texto));
401+
raise Exception.Create('Recurso em implementação');
402+
//Texto := FormataBits(SomenteNumero(Texto));
411403

412404
CEP:
413405
Texto := Mask('99.999-999', SomenteNumero(Texto));
@@ -437,7 +429,7 @@ function TFormatHelper.Formatar(Formato: TFormato; Texto: string;
437429
Texto := Mask('999999999-9', SomenteNumero(Texto));
438430

439431
CRM:
440-
Texto := FormataCRM(Ultimos(SomenteNumero(Texto), 6).ToInteger, ExtraArg);
432+
Texto := FormataCRM(StrToIntDef(Ultimos(SomenteNumero(Texto), 6), 0), ExtraArg);
441433

442434
Dinheiro:
443435
if ExtraArg <> varNull then
@@ -448,7 +440,7 @@ function TFormatHelper.Formatar(Formato: TFormato; Texto: string;
448440
Hora:
449441
Texto := FormataHora(SomenteNumero(Texto));
450442

451-
hhmm:
443+
HoraCurta:
452444
Texto := FormataHoraCurta(SomenteNumero(Texto));
453445

454446
InscricaoEstadual:
@@ -458,7 +450,7 @@ function TFormatHelper.Formatar(Formato: TFormato; Texto: string;
458450
Texto := Mask('9999.99.99', SomenteNumero(Texto));
459451

460452
OAB:
461-
Texto := FormataOAB(Ultimos(SomenteNumero(Texto), 6).ToInteger, ExtraArg);
453+
Texto := FormataOAB(StrToIntDef(Ultimos(SomenteNumero(Texto), 6), 0), ExtraArg);
462454

463455
Personalizado:
464456
Texto := Mask(ExtraArg, SomenteNumero(Texto));
@@ -467,7 +459,7 @@ function TFormatHelper.Formatar(Formato: TFormato; Texto: string;
467459
Texto := FormataPeso(SomenteNumero(Texto));
468460

469461
Porcentagem:
470-
Texto := Format('%.2f %s', [Decimal(Texto, 2), '%']);
462+
Texto := Format('%.2f %%', [StrToIntDef(SomenteNumero(Texto), 0)/100]);
471463

472464
Telefone:
473465
if Length(SomenteNumero(Texto)) <= 10 then
@@ -609,7 +601,7 @@ function TEditHelper.AlfaNumerico: string;
609601

610602
function TEditHelper.Decimal: string;
611603
begin
612-
Result := Formato.Decimal(Self.Text, 2).ToString;
604+
Result := FloatToStr(Formato.Decimal(Self.Text, 2));
613605
Self.SelStart := Length(Self.Text);
614606
end;
615607

0 commit comments

Comments
 (0)