Máscara em célula no DBGrid

Delphi

18/09/2009

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

Curtidas 0

Respostas

Leufmt

Leufmt

18/09/2009

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;


GOSTEI 0
Marco Salles

Marco Salles

18/09/2009

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


GOSTEI 0
Dbergkamps10

Dbergkamps10

18/09/2009

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

Espero ter ajudado.

Att
Dalton


GOSTEI 0
POSTAR