1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
procedure TF_Parametre.MasqueSaisie(Sender: TObject; var Key: Char);
{ Filtre sur la saisie d'une valeur numérique dans un TEdit }
var
texte : String;
begin
With Sender As TEdit Do
Begin
texte:=text;
{ La saisie d'une lettre n'est pas acceptée : }
if not (Key in ['0'..'9',',','.','-',#8,#13]) then Key := #15;
{ Interdiction de la saisie de plusieurs virgules successives :
en outre, la saisie d'un point est remplacée par une virgule : }
if (Key = ',') or (Key = '.') then
if (Pos(',',Texte) > 0) or (Pos('.',Texte) > 0) then
Key := #15
else
Key := DecimalSeparator;
{ un point (une virgule) sera toujours précédé de 0 : }
if (Key = ',') or (Key = '.') then
if length(texte)<1 then
Begin
text:='0,';
selstart:=2;
Key :=#0;
end;
if (Key = ',') or (Key = '.') then
if ((length(texte)<2) And (copy(texte,1,1)='-')) then
Begin
text:='-0,';
selstart:=3;
Key :=#0;
end;
{ pas d'espace : }
if Key = #32 then Key := #15;
{ ni de tiret : }
if Key = '-' then if ((length(Texte) > 0)And(SelStart >1)) then Key := #15;
if Key <> #0 then inherited KeyPress(Key);
End ;
{ Suppression de certaines touches qui sonnent dans le Edit des champs }
If Ord(Key)=13 Then Key := Chr(0) ;
end;
{ ======================================================================= }
procedure TF_Parametre.MasqueSaisieInt(Sender: TObject; var Key: Char);
{ Saisie d'une valeur numérique entiére positive }
var
texte : String;
begin
With Sender As TEdit Do
Begin
texte:=text;
{ La saisie d'une lettre n'est pas acceptée : }
if not (Key in ['0'..'9',#8,#13]) then Key := #15;
{ pas d'espace : }
if Key = #32 then Key := #15;
{ ni de tiret : }
if Key = '-' then if (length(Texte) > 0) then Key := #15;
{ Pas de 0 en première position: }
if (Key = '0') then
if length(texte)<1 then Key := #15;
if Key <> #0 then inherited KeyPress(Key);
End ;
{ Suppression de certaines touches qui sonnent dans le Edit des champs }
If Ord(Key)=13 Then Key := Chr(0) ;
end;
{ ======================================================================= } |
Partager