Показать сообщение отдельно
  #7  
Старый 18.05.2013, 23:41
Аватар для Bargest
Bargest Bargest вне форума
Профессионал
 
Регистрация: 19.10.2010
Адрес: Москва
Сообщения: 2,390
Версия Delphi: XE3/VS12/FASM
Репутация: 14665
По умолчанию

Да че там делать:
Код:
TFlagContainer = class
   data : byte;
 public
   procedure setData(id : integer; value : boolean);
   function getData(id : integer) : boolean;
end;

procedure TFlagContainer.setData(id : integer; value : boolean);
begin
   if id >= 8 then
       exit;
   data := data and not (1 shl id);
   if value then
      data := data or (1 shl id);
end;

function TFlagContainer.getData(id : integer) : boolean;
begin
   if ((data shr id) and 1) = 1 then
       result := true
   else
       result := false;
end;
EDIT: Для любителей "покороче":
Код:
TFlagContainer = class
   data : byte;
 public
   procedure setData(id : integer; value : boolean);
   function getData(id : integer) : boolean;
end;

procedure TFlagContainer.setData(id : integer; value : boolean);
begin if id < 8 then data := data and not (1 shl id) or ((Byte(value) and 1 ) shl id); end;

function TFlagContainer.getData(id : integer) : boolean;
begin result := ((data shr id) and 1) = 1; end;
__________________
jmp $ ; Happy End!
The Cake Is A Lie.
Ответить с цитированием