Einzelnen Beitrag anzeigen

Tyrael Y.

Registriert seit: 28. Jul 2003
Ort: Stuttgart
1.093 Beiträge
 
Delphi 2007 Professional
 
#10

Re: Anzahl Elemente in "set of"

  Alt 8. Apr 2009, 12:33
Ich benutze folgende Funktion, die halt wie hier beschrieben itteriert.

Delphi-Quellcode:
// anzahl := GetCountOfSetElements(@mySet, sizeof(mySet));
function GetCountOfSetElements(APointerToSet: Pointer; SizeOfSet: Cardinal): Cardinal;
const C_LOOKUP : packed array[0..15] of Byte = (0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4);
var LByte: Byte;
begin
  Result := 0;

  while SizeOfSet > 0 do
  begin
    LByte := PByte(APointerToSet)^;

    Inc(Result, C_LOOKUP[LByte and $0F]);
    Inc(Result, C_LOOKUP[LByte shr 4]);

    Dec(SizeOfSet);
    Inc(PByte(APointerToSet));
  end;
end;
Levent Yildirim
Erzeugung von Icons aus Bildern:IconLev
  Mit Zitat antworten Zitat