Código
//Text -> edit1.Text
//Key -> Key,, tecla precionada
//Espaco -> tamanho final da string
//Decimal -> casas decimais da string
Exemplo de como essa função deve ser chamada:
if (Key in ['0'..'9', #8]) then
Edit1.Text := fAlinhaD( Edit1.Text, Key, '12', '2' );
Function fAlinhaD( const Texto, Key, Espaco, Decimal : String ): String;
Var
vChar, vDiv : String;
I : Integer;
begin
vDiv := '1';
For I := 1 to StrToInt( Decimal )do
vDiv := vDiv + '0';
vChar := IfThen( Key = #8, copy( Texto, 1, length( Texto )- 1 ), Texto + Key );
While ( pos( ',', vChar ) > 0 ) or ( pos( '.', vChar ) > 0 ) do
begin
Delete( vChar, pos( '.', vChar ), 1 );
Delete( vChar, pos( ',', vChar ), 1 );
end;
if vChar = '' Then
vChar := '0';
Result := format('%'+Espaco+'.'+Decimal+'n',[strtofloat( vChar )/StrToInt( vDiv )]);
End;
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009