Bacterius a écritB and A = A excuse ... B and A <> 0 fonctionne quand on vérifie un seul bit
en fait ça fonctionne pour les deux.
la plupart des Dev utilisent "B and A > 0" mais je trouve que c'est plus parlant quand on relis un code :"if (B and A) = A then"
que "if (B and A) <> 0 then"
sinon avec cette méthode on peut (par exemple) stocker 32 valeurs Boolean dans un entier non signé.
Les composants sont "Tagés" de 0 à 31 (Maximum):
Code Delphi :
function Tfrm_Main.GetCheckedComponents: Cardinal;
var
Idx: Integer;
begin
Result :=
0;
for Idx :=
0 to ComponentCount -
1 do
if Components[Idx]
is TCheckBox
then
begin
with TCheckBox(Components[Idx])
do
if Checked
then
Result := Result
or (
1 shl Tag);
end
else if Components[Idx]
is TRadioButton
then
begin
with TRadioButton(Components[Idx])
do
if Checked
then
Result := Result
or (
1 shl Tag);
end;
end;
// la récupération des Valeurs se fait comme ceci:
procedure Tfrm_Main.SetCheckedComponents(Value: Cardinal);
var
Idx: Integer;
begin
for Idx :=
0 to ComponentCount -
1 do
if Components[Idx]
is TCheckBox
then
begin
with TCheckBox(Components[Idx])
do
Checked := (Value
and (
1 shl Tag)) >
0;
end
else if Components[Idx]
is TRadioButton
then
begin
with TRadioButton(Components[Idx])
do
Checked := (Value
and (
1 shl Tag)) >
0;
end
end;
@+Cirec