Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
prog:lazarus:types:enum [07/05/2020 14:40]
thierry [Comment sont ils stocké en mémoire ?]
prog:lazarus:types:enum [15/09/2024 13:15] (Version actuelle)
thierry [Opérateur * pour verifier plusieurs membres du Set]
Ligne 55: Ligne 55:
      x:= GetEnumName(TypeInfo(TMonthType),​ Ord(i));      x:= GetEnumName(TypeInfo(TMonthType),​ Ord(i));
   end;   end;
 +</​code>​
 +
 +<code pascal>
 +var
 +  vHandlerType:​ TDragManagerHandlerType;​
 +begin
 +  for vHandlerType := Low(TDragManagerHandlerTypee) to High(TDragManagerHandlerType) do
 +    FreeThenNil(FDragManHandlers[vHandlerType]);​
 +end;         
 </​code>​ </​code>​
 == Passer d'un Type énuméré a un ordinale et réciproquement == == Passer d'un Type énuméré a un ordinale et réciproquement ==
Ligne 81: Ligne 90:
   TMonths = set of TMonth; ​             ​   TMonths = set of TMonth; ​             ​
               ​               ​
-</​code> ​     +</​code> ​   
 +==== In ==== 
 +on peut tester si un membre fait parti d'un SetOf avec l'​operateur IN. 
 +<code delphi>​ 
 +Months: TMonths 
 +... 
 +if January in Months then... 
 +</​code>​ 
 + 
 +==== Opérateur * pour verifier plusieurs membres du Set ==== 
 +<code pascal>​ 
 +if [csLoading,​csDestroying,​csDesigning]*ComponentState=[] then ... 
 +</​code>​ 
 + 
 +==== Include / Exclude ==== 
 +<code pascal>​ 
 +Include (FComponentState,​csUpdating);​  
 +... 
 +Exclude(FComponentState,​csUpdating);​ 
 + 
 +</​code>​ 
 + 
 + 
 +   
 ==== Comprendre les sets ==== ==== Comprendre les sets ====
 === Comment sont ils stocké en mémoire ? === === Comment sont ils stocké en mémoire ? ===
Ligne 137: Ligne 169:
 end. end.
 </​code>​ </​code>​
 +=== Passer d'un Integer en Set of ===
 +Tout se passe dans la procedure ''​IntAsSet''​ ci-dessous...
 +<code delphi>
 +program project2;
 +
 +uses
 +   ​sysutils;​
 +
 +type
 +   ​TBit ​  = (b0, b1, b2, b3, b4, b5, b6, b7);
 +   ​TBits ​ = set of TBit;
 +var
 +   ​vS: ​   string;
 +   ​vBits:​ TBits;
 +   ​pI: ​   pinteger;
 +
 +   ​procedure test(ABits: TBits);
 +   var
 +      //vBit: TBit;
 +      vI: integer;
 +   begin
 +      for vI := Ord(low(TBit)) to Ord(high(TBit)) do
 +      begin
 +         if TBit(vI) in ABits then
 +            writeln(IntToStr(vI) + ' = 1')
 +         else
 +            writeln(IntToStr(vI) + ' = 0');
 +      end;
 +   end;
 +
 +   ​procedure IntAsSet(AInt:​ integer; PSet: pointer);
 +   var
 +      pI: pInteger;
 +   begin
 +      pI  := PSet;
 +      pI^ := Aint;
 +   end;
 +
 +
 +begin
 +
 +   vBits := [];  //​(00000000...)
 +   ​IntAsSet(255,​ @vBits);
 +   ​test(vBits);​
 +
 +   ​ReadLn(vS);​
 +end.                  ​
 +</​code>​
 +