tu peux le faire avec un tableau et AnsiMatchStr
1 2 3 4
| const
TYPE_PERIODE: array[0..3] of string = ('Mensuel' , 'Trimestriel' , 'Semestriel' , 'Annuel' );
TYPE_PERIODE_RATIO: array[0..3] of Integer = (12, 4, 2, 1);
... |
CurrencyEdit1.Value:= CurrencyEdit2.Value / TYPE_PERIODE_RATIO[AnsiMatchStr(ComboBox1.Text, TYPE_PERIODE)];
tu peux aussi faire un Case ... cela évite la division par 1 ou un type non prévu
1 2 3 4 5 6 7 8
| case AnsiMatchStr(ComboBox1.Text, TYPE_PERIODE) of
0: CurrencyEdit1.Value:=CurrencyEdit2.Value / 12;
1: CurrencyEdit1.Value:=CurrencyEdit2.Value / 4;
2: CurrencyEdit1.Value:=CurrencyEdit2.Value / 2;
3: CurrencyEdit1.Value:=CurrencyEdit2.Value;
else
Merdoum !
end; |
Tu peux encore tricher, en mettant le ComboBox1 en Style à csDropDownList, et en utilsant l'ItemIndex
1 2 3 4 5 6 7 8
| case ComboBox1.ItemIndex of
0: CurrencyEdit1.Value:=CurrencyEdit2.Value / 12;
1: CurrencyEdit1.Value:=CurrencyEdit2.Value / 4;
2: CurrencyEdit1.Value:=CurrencyEdit2.Value / 2;
3: CurrencyEdit1.Value:=CurrencyEdit2.Value;
else
Merdoum !
end; |
Faut juste faire attention, que l'ordre ne change pas, en général, j'utilise un remplissage manuel (pas dans la DFM, en code) et une énumération
Partager