GARANTIR DESCONTO

Fórum Máscara em célula no DBGrid #375065

18/09/2009

0

Estou com o seguinte problema:
Tenho uma unit para mascarar campos como: CPF. CNPJ, Data, ...
para usar faço o seguinte:
procedure TFormCliente.DBEDataKeyPress(Sender: TObject; var Key: Char);
begin
Mascara_Data(Key, Sender);
end;

O problema começa em como faço para utilizar esta máscara em um campo no DBGrid? Pois do DBGrid eu digito os dados.

No DBGrid coloco desta maneira, só que não acontece nada quando digito a data.
procedure TFormOrcamento.DBGProdutosKeyPress(Sender: TObject;
var Key: Char);
begin
If DBGProdutos.SelectedField.FieldName = ´PRAZOENTREGA_OIT´ then
begin
If ADOQOrcamentoItensF.State in [dsEdit, dsInsert] then
Mascara_Data(Key, Sender);

end;
end;

Desde já agradeço a atenção companheiros.


Leufmt

Leufmt

Responder

Posts

18/09/2009

Leufmt

Complementando. Ai vai o código:

function Mascara_Data(var Key: char; Sender: TObject): String;
begin
If not(Key in[´0´..´9´, #8, 13]) then
Key := 0;

If Key <> 8 then
begin
Case Length(TCustomEdit(Sender).Text) of
2: begin
If not (Key in [´0´..´9´]) then
Key := 0;

TCustomEdit(Sender).Text := TCustomEdit(Sender).Text + ´/´;
TCustomEdit(Sender).SelStart := Length(TCustomEdit(Sender).Text);
end;
5: begin
If not (Key in [´0´..´9´]) then
Key := 0;

TCustomEdit(Sender).Text := TCustomEdit(Sender).Text + ´/´;
TCustomEdit(Sender).SelStart := Length(TCustomEdit(Sender).Text);
end;
end;
end;
end;


Responder

Gostei + 0

18/09/2009

Marco Salles

Mas pq vc não usa o maskedit do tfield ... Ao inves de ficar criando funçoes
para isto... ???


Responder

Gostei + 0

19/09/2009

Dbergkamps10

Olá,
leufmt, vc pode mascarar direto na propriedade EditMask no campo do Data Set, através do objetc inspector.

Espero ter ajudado.

Att
Dalton


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar