Funções usadas para gerar arquivos textos
{Moeda}
function FormatVar(AValue: Currency; ALength: Integer): String;overload;
Begin
{Essa função retorna um string de um campo tipo moeda com zeros a esqeuerda
nesse caso usando FormatFloat com o formato 0 para todas as posições e multiplicando
o valor por 100 para eliminar a virgula decimal.
Ex.: Passando FormatVar(100,25, 8) para a funcao o retorno será:
00010025}
Result := FormatFloat(StringOfChar('0', Alength), AValue * 100);
End;
{Data e hora}
function FormatVar(AValue: TDate; AFormat: String): String;overload;
Begin
{Formata um campo do tipo data e hora o parametro formato sao os mesmos da funcao FormatDateTime}
Result := FormatDateTime(AFormat, Avalue);
End;
{Texto geral}
function FormatVar(AValue: String; ALength: Integer; AJustify: String = 'LEFT'): String;overload;
Var
iLength: Integer;
Begin
{essa função preenche com espaços a direita ou a esquerda
passando o parametro AJustify como Left o texto será alinhado a esquerda com espaços a direita}
iLength := Length(Trim(AValue));
Result := Trim(AValue);
If AJustify = 'LEFT' Then
Result := Result + StringOfChar(#32, ALength - iLength);
If AJustify = 'RIGHT' Then
Result := StringOfChar(#32, ALength - iLength) + Result;
Result := CopyLeft(Result, Alength);
End;
{Inteiros}
function FormatVar(AValue: Integer; ALength: Integer): String;overload;
Begin
{retorna uma String de um inteiro com zeros a esquerda}
Result := FormatFloat(StringOfChar('0', Alength), AValue);
End;
{Cnpj ou Cpf}
function FormatCnpjCpf(AValue: String): String;
Var
iLength: Integer;
Begin
teiros}
iLength := Length(Trim(AValue));
Result := StringOfChar('0', 15 - iLength) + Trim(AValue);
End;
{CopyLeft}
function CopyLeft(AString: String; ALength: Integer): String;
Var
i: Integer;
Begin
{Retorna uma SubString da direita para esquerda no tamamnho desejado
For i := 1 To Length(AString) Do
If i > ALength Then
Break
Else
Result := Result + AString[i];
End;
{CopyRight}
function CopyRight(AString: String; ALength: Integer): String;
Var
i: Integer;
Begin
For i := Length(AString) DownTo 1 Do
If (Length(AString) - i) >= ALength Then
Break
Else
Result := AString[i] + Result;
End;