unit conver;

interface
uses
SysUtils,DB;
function convierte(formateo,cantidad,tipo:String):String;
function tipocampo(tipo:TFieldType):Char;
function mesletra(m:word):String;
function diasxmes(m:word;bisiesto:Boolean):word;
function subcadena(cadena:string;inicio,termino:word):string;
function Flotante(cad:string):Real;
implementation

function Flotante(cad:string):Real;
begin

if (cad='')or(cad='f')or(cad='e')or(cad='x') then Flotante:=0
else
begin
{val(cad,}
Flotante:=StrToFloat(cad);
end;

end;


function subcadena(cadena:string;inicio,termino:word):string;
var
aux:string;
i:integer;
begin
aux:='';
for i:=inicio to termino do
begin
aux:=aux+cadena[i];
subcadena:=aux;
end;


end;

function mesletra(m:word):String;
begin
case m of
1:mesletra:='Ene';
2:mesletra:='Feb';
3:mesletra:='Mar';
4:mesletra:='Abr';
5:mesletra:='May';
6:mesletra:='Jun';
7:mesletra:='jul';
8:mesletra:='Ago';
9:mesletra:='Sep';
10:mesletra:='Oct';
11:mesletra:='Nov';
12:mesletra:='Dic';
end;

end;

function diasxmes(m:word;bisiesto:Boolean):word;
begin
case m of
1:diasxmes:=31;
2:if bisiesto then diasxmes:=29 else diasxmes:=28;
3:diasxmes:=31;
4:diasxmes:=30;
5:diasxmes:=31;
6:diasxmes:=30;
7:diasxmes:=31;
8:diasxmes:=31;
9:diasxmes:=30;
10:diasxmes:=31;
11:diasxmes:=30;
12:diasxmes:=31;
end;

end;

function tipocampo(tipo:TFieldType):Char;
var
caso:char;
begin
case tipo of
ftString:begin tipocampo:='c'; end;
ftBlob:tipocampo:='c';
ftTime:tipocampo:='c';
ftSmallint:tipocampo:='e';
ftInteger:tipocampo:='e';
ftBytes:tipocampo:='e';
ftFloat:tipocampo:='f';
ftWord:tipocampo:='w';
ftVarBytes:tipocampo:='b';
ftCurrency:tipocampo:='$';
ftAutoInc:tipocampo:='c';
ftGraphic:tipocampo:='g';
ftBoolean:tipocampo:='c';
ftBCD:tipocampo:='c';
ftMemo:tipocampo:='c';
ftDate:tipocampo:='d';
ftDateTime:tipocampo:='d';
else
tipocampo:='x';
end;


end;



Function convierte(formateo,cantidad,tipo:String):String;
var
num,aux,agre:string;
i,cuenta:integer;
begin

if tipo='f' then tipo:='$';
{else }
if (tipo<>'c') then
begin
{if tipo='f' then tipo:='$';}

agre:='';
if cantidad='' then
cantidad:='0';
agre:='';

aux:=FormatCurr(formateo,StrToCurr(cantidad));
if length(aux)<length(formateo) then
begin
for i:=1 to length(formateo)-length(aux) do
aux:=' '+aux;
end;

{if tipo=1 then
convierte:='$'+agre+aux
else
convierte:=agre+aux;}
convierte:=tipo+agre+aux;
end
else
convierte:=cantidad;

{MuestraMensaje(aux);}
end;

end.
